什么相当于jQuery中的'getElementsByTagName'? [英] What's the equivalent of 'getElementsByTagName' in jQuery?
本文介绍了什么相当于jQuery中的'getElementsByTagName'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jQuery中的 getElementsByTagName()
相当于什么?我只是想在jQuery中创建一个元素集合,所以我可以遍历它们并对每个项目做一些事情。
What's the equivalent of getElementsByTagName()
in jQuery? I just want to create a collection of elements in jQuery so I can iterate through them and do something with each item.
非常感谢!
推荐答案
$("tagnamehere")
所以:
$("div").each(function() {
// do something exciting with each div
$(this).css("border", "1px solid red");
// do something by directly manipulating the wrapped DOM element
this.style.border = "1px solid red";
// do something only if this particular div has a class of 'pretty'
if($(this).hasClass("pretty")) {
$(this).text("I am the pretty one");
}
});
或只是:
// apply some css to all div elements
$("div").css("border", "1px solid red");
请记住,当您使用jQuery选择多个元素时,例如: $(span)
,您在对象上调用的任何方法都将发生在所有匹配的元素上。将其视为隐式迭代 - 例如 $(span)。hide();
将隐藏页面上的所有span元素。
Keep in mind that when you use jQuery to select a number of elements, e.g. $("span")
, any method you invoke on the object will happen on all matched elements. Think of it as 'implicit iteration' - e.g. $("span").hide();
will hide all span elements on the page.
请参阅:
- http://www.w3.org/TR/css3-selectors/
- http://api.jquery.com/category/selectors/
- http://api.jquery.com/each/
- http://www.w3.org/TR/css3-selectors/
- http://api.jquery.com/category/selectors/
- http://api.jquery.com/each/
这篇关于什么相当于jQuery中的'getElementsByTagName'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文