I have a <div> like below
<div class="divClass">
<ul class="ulClass">
<li id="liID" class="liClass">
<a href="myLink">
<span class="spanClass">myText</span>
</a>
</li>
</ul>
</div>
Now I want to write a jQuery script to read the <a> element and set the value of target attribute to _blank.
I went through JQuery change atributes of child elements and got a script. But, it gave me a script like below
$('.divClass').click(function(e){
$(this).find('.aclass').text("yeeee");
$(this).find('.imgclass').attr("src", "remove_favorit.png");
e.preventDefault();
});
What I actually want is iterate through <div>, <ul>, <li> and then reach out to the <a> in it and set the target. How can I do this?
I also went through Get attribute of child element
I think you don’t want it to happen on click but following code will set the
target=_blankon clicking on a link insidedivClassAnd this code will do it on page load