select onclick that contains _blank

2019-08-12 07:00发布

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>

3条回答
Viruses.
2楼-- · 2019-08-12 07:13

Use below code :

jQuery('a[onclick*="_blank"]').attr('title', 'New window');
查看更多
\"骚年 ilove
3楼-- · 2019-08-12 07:19

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

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

Could you use that instead?

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

查看更多
可以哭但决不认输i
4楼-- · 2019-08-12 07:29

found that contains is * and not ~

jQuery("a[onclick*='_blank']").attr('alt', 'New window');
查看更多
登录 后发表回答