Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: How to select only within a selection?

Tags:

var parent = $("#jcontent"); var button1 = parent(".button1") 

How to select .button1 knowing it is inside the parent while not reusing #jcontent?

I need to do this because I only want to pass the parent as parameter and to be able to cache it which is faster.

like image 885
Totty.js Avatar asked Dec 16 '10 20:12

Totty.js


People also ask

How do you select a particular option in a select element in jQuery?

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”).

How do I find the element inside a div?

You can use the children property of getElementById() method in JavaScript to get or extract unique ids of all the DIV elements inside a DIV element.

How do I select elements when I already have a DOM element?

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.

How will you select only the odd anchor tags on the page?

The :odd selector selects each element with an odd index number (like: 1, 3, 5, etc.). The index numbers start at 0. This is mostly used together with another selector to select every odd indexed element in a group (like in the example above). Tip: Use the :even selector to select elements with even index numbers.


1 Answers

Another alternative

var parent = $("#jcontent");  var button1 = $(".button1", parent) ; 
like image 141
Chandu Avatar answered Jan 15 '23 09:01

Chandu