Home >Web Front-end >JS Tutorial >When loading the list, jquery gets the attributes of the first li in ul_jquery

When loading the list, jquery gets the attributes of the first li in ul_jquery

WBOY
WBOYOriginal
2016-05-16 16:32:231853browse

When loading the list, you want to select the first item by default. top_menu is the ID of ul

You can get the first li tag under ul through $("#top_menu li:first"). Then you can use

For example, modify attributes: $("#top_menu li:first").attr("class","select");

Trigger event: $("#top_menu li:first").click();

If you want to get the a tag under li, as follows:

$("#top_menu li:first a")

You can also modify the attributes: $("#top_menu li:first a").attr("","");

Trigger event: $("#top_menu li:first a").click();

Copy code The code is as follows:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn