jQuery AJAX cross domain

Use JSONP. jQuery: PHP: The echo might be wrong, it’s been a while since I’ve used php. In any case you need to output callbackName(‘jsonString’) notice the quotes. jQuery will pass it’s own callback name, so you need to get that from the GET params. And as Stefan Kendall posted, $.getJSON() is a shorthand method, but then you need to … Read more

What is different between $(document).on() and $(element).on()

Main difference is already answered by @Mukesh. I will try to add one more thing. When you click(or any other event) on an element(like div or button) in the html document, that clicking event is propagated to the parent elements of that element. So if you have structure like this: and you click on the button, that click … Read more

Uncaught TypeError: $.post is not a function

You are using the slim version of jQuery, which doesn’t include the Ajax methods (in your case $.post()). Use the non-slim build, available here http://jquery.com/download/, such as: https://code.jquery.com/jquery-3.5.1.min.js From jQuery 3.0 release post: Slim build […] Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests.[…] Along with the regular version of … Read more

Get class name using jQuery

After getting the element as jQuery object via other means than its class, then should do the trick. For the ID use .attr(‘id’). If you are inside an event handler or other jQuery method, where the element is the pure DOM node without wrapper, you can use: Both are standard DOM methods and well supported in … Read more

Disable/enable an input with jQuery?

jQuery 1.6+ To change the disabled property you should use the .prop() function. jQuery 1.5 and below The .prop() function doesn’t exist, but .attr() does similar: Set the disabled attribute. To enable again, the proper method is to use .removeAttr() In any version of jQuery You can always rely on the actual DOM object and is probably a little faster than the other two … Read more

JavaScript: filter() for Objects

Never ever extend Object.prototype. Horrible things will happen to your code. Things will break. You’re extending all object types, including object literals. Here’s a quick example you can try: Instead create a function that you pass the object.