developer

Clear form fields with jQuery

Question: ❓❓❓ I want to clear all input and textarea fields in a form. It works like the following when using an input button with the reset class: $(".reset").bind("click", function() { $("input[type=text], textarea").val(""); }); This will clear all fields on the page, not just the ones from the form. How Read more…

By admin, ago
developer

Listening for variable changes in JavaScript

Question: ❓❓❓ Is it possible to have an event in JS that fires when the value of a certain variable changes? JQuery is accepted. Thanks! Good Answer: 👌👌👌 Yes, object.watch (it’s non-standard though). Here’s my implementation that works in every current major browser. Read More: 👉 https://stackoverflow.com/questions/1759987/listening-for-variable-changes-in-javascript

By admin, ago
developer

jQuery – multiple $(document).ready …?

Question: ❓❓❓ Question: If I link in two JavaScript files, both with $(document).ready functions, what happens? Does one overwrite the other? Or do both $(document).ready get called? For example, <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script type="text/javascript" src="http://.../jquery1.js"></script> <script type="text/javascript" src="http://.../jquery2.js"></script> jquery1.js : $(document).ready(function(){ $("#page-title").html("Document-ready was called!"); }); jquery2.js: $(document).ready(function(){ $("#page-subtitle").html("Document-ready was called!"); Read more…

By admin, ago
developer

Get checkbox value in jQuery

Question: ❓❓❓ How can I get a checkbox’s value in jQuery? Good Answer: 👌👌👌 To get the value of the Value attribute you can do something like this: $("input[type='checkbox']").val(); Or if you have set a class or id for it, you can: $('#check_id').val(); $('.check_class').val(); However this will return the same Read more…

By admin, ago
developer

jQuery $.ajax(), $.post sending “OPTIONS” as REQUEST_METHOD in Firefox

Question: ❓❓❓ Having trouble with what I thought was a relatively simple jQuery plugin… The plugin should fetch data from a php script via ajax to add options to a <select>. The ajax request is pretty generic: $.ajax({ url: o.url, type: 'post', contentType: "application/x-www-form-urlencoded", data: '{"method":"getStates", "program":"EXPLORE"}', success: function (data, Read more…

By admin, ago
developer

Can I find events bound on an element with jQuery?

Question: ❓❓❓ I bind two event handlers on this link: <a href='#' id='elm'>Show Alert</a> JavaScript: $(function() { $('#elm').click(_f); $('#elm').mouseover(_m); }); function _f(){alert('clicked');} function _m(){alert('mouse over');} Is there any way to get a list of all events bound on an element, in this case on element with id="elm"? Good Answer: 👌👌👌 Read more…

By admin, ago