I believe most people will use these two incorrectly. You can find out by carefully checking the API documentation. eq returns a jqueryobject, and get returns an html objectarray.
For example:
Feiyu
Use eq to get the color value of the first p tag:The code is as follows:
<ul> <li>li-1</li> <li>li-2</li> </ul>
For example, if we pass the jquery selector $("li"), then we will have two How can I only select one of the li elements?
$("li:eq(0)").html() or $("li").eq(0).html() is The first li here we will get li-1
$("li:eq(1)").html() or $("li").eq(1).html() which is the second li Here we will get li-2
Let’s look at get because get returns an html object, so here we are
$("li").get(0).style.color='red'
You can only use this or convert the get return object into a jquery object and operate
$($("li").get(0)).css("color",'red')
Complete code
The code is as follows:
< HEAD >New Document <ul> <li>li-1</li> <li>li-2</li> </ul>
The above is the detailed content of The difference and usage between eq and get in jquery. For more information, please follow other related articles on the PHP Chinese website!