English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In development, we sometimes add attributes to html tags, how to traverse and process them?
<ul> <li name="li1" sortid="nav_1">aaaaaaa</li> <li name="li1" sortid="nav_2">bbbbbbb</li> <li name="li1" sortid="nav_3">cccccccc</li> <li name="li1" sortid="nav_4">ddddddd</li> <li name="li1" sortid="nav_5">eeeeeee</li> <li name="li1" sortid="nav_6">fffffffffffffffff</li> <li name="li1" sortid="nav_7">gggggggg</li> <li name="li1" sortid="nav_8">hhhhhhhh</li> <li name="li1" sortid="nav_9">iiiiiiiiiiiiiiiiiii</li> </ul> //Traversal by sortid $("li[sortid^='nav_']").each(function(i){ var sortid=$(this).attr("sortid"); }); //Traversal by name $("[name=li1']).each(function(a,b){ var sortid= $(b).attr("sortid"); }); //If a certain sortid is known to take the object $("[sortid='nav_1']).attr("html"); $("[sortid='nav_1']).attr("name");
Other:
//Find the text object with the name clssId $("input[name='clssId']").val(); //Find id with certain regularity, for example, find dd tag with id=single_xxx $("dd[id^=single_]").each(function(){ var id = $(this).attr("id"); alert(id.substring(7)); });
This is the complete content of the custom attribute method of jQuery traversal tag shared by the editor. I hope it can provide a reference for everyone and everyone is welcome to support the Yell Tutorial.