I’m a noob at Jquery so forgive me if this is ridiculous, but does get() and [] break the method chain ? I’m attempting to retrieve a single element from a returned Jquery Object :
<HTML>
<HEAD><TITLE>A test page</TITLE></HEAD>
<BODY>
<p>This is a paragraph</p>
<p>This is a second paragraph</p>
</BODY>
</HTML>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var x = $("p").get(1).text(); //This doesn't work
var y = $($("p").get(1)).text(); //re-wrapping the result does however.
</script>
If this is the case, how do I more succinctly retrieve a designated value, because at the moment the approach I’m using above is a little clunky to say the least.
Yes, it breaks,
getconverts the jQuery object to a DOM Element object then you cannot use jQuery methods on the selected elements, you can useeq()method instead:or
:eq()selector:Note that
getandeqmethods are zero-based,eq(1)selects the second element.