jQuery selectors: logical OR
It’s the same as in CSS selectors: $(‘.headsection, .subtitle’);
It’s the same as in CSS selectors: $(‘.headsection, .subtitle’);
You can use .eq() with a negative value (-1 is last) to get n from the end, like this: $(“.album li”).eq(-2).attr(“id”); // gets “li-9” You can test it here.
This should do it I think $(“#formId input:text, #formId textarea”).first().focus();
Determine the .next() ahead of time by checking its length property. $(‘.nextSingle’).click( function() { // Cache the ancestor var $ancestor = $(this).parent().parent().parent(); // Get the next .newsSingle var $next = $ancestor.next(‘.newsSingle’); // If there wasn’t a next one, go back to the first. if( $next.length == 0 ) { $next = $ancestor.prevAll(‘.newsSingle’).last();; } //Get the … Read more
If you were doing this with regex, the expression would simply be: item-\d-top Where the \d indicates any single digit (0..9), and the other characters have no special meaning (so are treated as literals). However, jQuery doesn’t currently have a regex filter (only things like start/end/contains/etc) – so you would have to create your own … Read more
The reason your code isn’t working is because [innerHTML] is an attribute selector, and innerHTML isn’t an attribute on the element (which means that nothing is selected). You could filter the span elements based on their text. In the example below, .trim() is used to trim off any whitespace. If the text equals ‘Category:’, then … Read more
use the selector :contains() var element = $(“label:contains(‘SuperSweetCheckbox’)”); The matching text can appear directly within the selected element, in any of that element’s descendants, or a combination thereof. As with attribute value selectors, text inside the parentheses of :contains() can be written as bare words or surrounded by quotation marks. The text must have matching … Read more
You should use :first-child instead of :first: Sounds like you’re wanting to iterate through them. You can do this using .each(). Example: $(‘td:first-child’).each(function() { console.log($(this).text()); }); Result: nonono nonono2 nonono3 Alernatively if you’re not wanting to iterate: $(‘td:first-child’).css(‘background’, ‘#000’); JSFiddle demo.
Using jQuery Selectors, you can target your element by a certain attribute matching the desired value: $(‘input[value=”Whatever”]’); This way you are targeting an input element, by the attribute value that is equal to the desired value. EDIT 5/14/2013: According to an answer below, this no longer works as of jQuery 1.9.
$(“a[href*=#]”).click(function(e) { e.preventDefault(); alert(‘works’); });