Get the selected option id with jQuery
You can get it using the :selected selector, like this: $(“#my_select”).change(function() { var id = $(this).children(“:selected”).attr(“id”); });
You can get it using the :selected selector, like this: $(“#my_select”).change(function() { var id = $(this).children(“:selected”).attr(“id”); });
You can apply more than one filter at a time, although the 2nd filter applies to the results of the first, so the following would highlight starting from the 4th row (skips 0..2), and highlight for 3 rows (includes 0..2): $(‘#t tr:gt(2):lt(3)’).css(‘background-color’, ‘#f00’);
The [0] array notation and the .get() method both return a reference to a DOM element within the jQuery object, and you can’t use jQuery methods on DOM elements. Try the eq() method instead, because it returns a new jQuery object: $(‘.foo’).eq(0).hide(); Note also that having used the array notation or .get() to get a … Read more
$(“#addNew_tab, #sendCom_tab”).click(function(){ //do stuff }); Changed from: $(“#addNew_tab”, “#sendCom_tab”) To: $(“#addNew_tab, #sendCom_tab”) comma inside the selector(“a, b”) means the first plus the second; Just like with CSS selectors (Well, it’s a CSS selector…) jQuery(selector) Description: Accepts a string containing a CSS selector which is then used to match a set of elements. It’s equal to: … Read more
jQuery 1.4 now has the .nextUntil(selector) function: $(‘div.parent’).toggle( function() { $(this).nextUntil(‘div.parent’).hide(); }, function() { $(this).nextUntil(‘div.parent’).show(); } );
Context really helps when you have a much larger DOM that you are searching through. Searching for IDs is already very fast and context doesn’t really help that much in that case. Where context can really make a difference is when you are selecting by tag name or class. Try testing like this: http://jsbin.com/aciji4/4 you … Read more
jQuery has added a utility for creating custom pseudos in Sizzle. It’s a little more verbose, but it’s much more readable than using match[3]. It also has the advantage of being more performant as you can avoid repeating tedious calculations every time an element is tested. The answer that has already been accepted is a … Read more
Billy’s answer is incredibly complete and actually worked quite well the few times I used it. Additionally however, you may want to look at the vmouse plugin in JQuery Mobile, it is an attempt to abstract mouse events: // This plugin is an experiment for abstracting away the touch and mouse // events so that … Read more
you can do $(“#\\/about-us”)
$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); if($.browser.chrome){ ………… } UPDATE:(10x to @Mr. Bacciagalupe) jQuery has removed $.browser from 1.9 and their latest release. But you can still use $.browser as a standalone plugin, found here