开发者

Select links with certain attribute

开发者 https://www.devze.com 2023-03-21 00:59 出处:网络
i am trying to sele开发者_StackOverflowct all links with a certain attribute, for some reason it dosent work, can anyone help ?

i am trying to sele开发者_StackOverflowct all links with a certain attribute, for some reason it dosent work, can anyone help ?

HTML

<a href="javascript:;" title="Edit">Edit</a>

JQUERY

$('a[title="Edit"]').click(function (e) {
    e.preventDefault;
    alert($(this).attr('title'));
})


Your attribute selector looks correct. I suspect you are failing to attach that click handler when the DOM is ready for JavaScript processing:

$(document).ready(function() {
    $('a[title="Edit"]').click(function (e) {
        e.preventDefault;
        alert($(this).attr('title'));
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消