For example I have a function that has one argument, it can be DOM element ID or className. How can I select only first element wrapped with jQuery?
$(value).get(0) and $(value)[0] returns just the plain DOM element, not a jQuery wrapped element.
For example I have a function that has one argument, it can be DOM element ID or className. How can I select only first element wrapped with jQuery?
$(value).get(0) and $(value)[0] returns just the plain DOM element, not a jQuery wrapped element.
$(value).eq(0);
// or
$(value).first();
// or
$(value + ':eq(0)');
// or
$(value + ':first');
$(value).first();
See http://api.jquery.com/first/
Given a jQuery object that represents a set of DOM elements, the
.first()method constructs a new jQuery object from the first matching element.
You can use :first (if it's a selector), like this:
$(value:first)
Or .eq(0) like this:
$(value).eq(0)
Or .first() (just an alias for .eq(0)) like this:
$(value).first()