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"
.开发者_JAVA技巧
How can i do this in using jquery?
Do 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');
精彩评论