Markup:
<div class="foo"> <img src="loading.gif" class="loading" style="display: none;" /> </div>
Js:
$("div[class='foo']").click(function(e) { e.preventDefault(); $(this).hide(); $(/* somehow select the loading img of exactly this div with class foo (not others) */).show(); });
If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object. var myDomElement = document. getElementById( "foo" ); // A plain DOM element.
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.
To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class.
Syntax of jQuery Select Option$("selector option: selected"); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $("selector option: selected").
$("div[class='foo']").click(function(e) { e.preventDefault(); $(this).hide(); $('img.loading', this).show(); });
If you want any descendant of the given element you can use find():
$(this).find(".foo");
If you know you only want to search for the first-level children elements, you can use children():
$(this).children(".foo");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With