admin管理员组文章数量:1289880
How to find all the anchor tags inside a div tag and need to append one more property to the anchor tag. say target="_blank"
.
How can i do this in using jquery?
How to find all the anchor tags inside a div tag and need to append one more property to the anchor tag. say target="_blank"
.
How can i do this in using jquery?
Share Improve this question edited Dec 23, 2013 at 4:21 Arul Dinesh 5504 silver badges15 bronze badges asked May 6, 2010 at 10:37 niminimi 5,50718 gold badges62 silver badges90 bronze badges4 Answers
Reset to default 5Do you mean all the anchors in any div element, or in some specific div element? If it's the former, this will do the trick:
$('div a').attr('target', '_blank');
If it's a particular div you're interested in, give that element an id attribute and then use it like so:
$('#divid a').attr('target', '_blank');
replacing "divid" with the id in question.
Can you be more specific about what exactly you want?
In any case, you're going to need to use the attr()
function to set the attribute; see the documentation here.
You are probably interested in a single div, not every div on page, so You have to identify it.
$('div#theDivsId a').attr('target','_blank');
or
$('div.theDivsClass a').attr('target','_blank');
PS. read documentation. it's easy.
jQuery("#yourDIV a").attr("target", "_blank");
Have you read the jQuery docs? This can't be more basic.
$('div a').attr('target','_blank');
本文标签: javascriptjquery to find all the elements inside a div tagStack Overflow
版权声明:本文标题:javascript - jquery to find all the elements inside a div tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741400452a2376634.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论