How do I add target=“_blank” to a link within a specified div?

前端 未结 7 1589
失恋的感觉
失恋的感觉 2020-11-27 03:29

Let\'s say I have the following code:


                      
相关标签:
7条回答
  • 2020-11-27 03:56

    Non-jquery:

    // Very old browsers
    // var linkList = document.getElementById('link_other').getElementsByTagName('a');
    
    // New browsers (IE8+)
    var linkList = document.querySelectorAll('#link_other a');
    
    for(var i in linkList){
     linkList[i].setAttribute('target', '_blank');
    }
    
    0 讨论(0)
提交回复
热议问题