Add attribute of href inside li with a particular data-id in jQuery

This question already has an answer here:

I need to add target="blank" to the a tag with li data-id="232"

<li class="" data-id="232">
    <a href="new.html">
    New Page    
  </a>
</li>

using jQuery.

Answers 1

  • You can use .attr with the following jQuery selector:

    $('li[data-id="232"] a').attr('target', '_blank')
    

Related Articles