select onclick that contains _blank

☆樱花仙子☆ 提交于 2019-12-24 15:58:31

问题


i select links with a blank target to set a title attribute

jQuery('a[target~="_blank"]').attr('title', 'New window');

that works.

But when i select the onclick attribute that doesn't work

jQuery('a[onclick~="_blank"]').attr('title', 'New window');

any clues?

the link looks like that:

<a onclick="javascript:this.target=&quot;_blank&quot;" title="" href="http://link.com">link</a>

回答1:


Use below code :

jQuery('a[onclick*="_blank"]').attr('title', 'New window');



回答2:


found that contains is * and not ~

jQuery("a[onclick*='_blank']").attr('alt', 'New window');



回答3:


This seems to work for me using the Attribute Contains Selector -

$("a[onclick*='_blank']")

Could you use that instead?

Demo - http://jsfiddle.net/uZaCW/



来源:https://stackoverflow.com/questions/7595227/select-onclick-that-contains-blank

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!