Anonimus
Anonimus

Reputation: 13

jQuery href tag

I'm trying to use a jQuery selector for the clicking the following link but it's not working out. Anyone have an answer? Thanks.

$tweet.html(tweet.created_at + ' <a href="#" class="'+tweet.user+'">@' + tweet.user + '</a>: ' + tweet.message);
$tweet.appendTo($body);
$("a[href*=#]").click(function(e) {
    e.preventDefault();
    alert('works');
});

Upvotes: 0

Views: 116

Answers (2)

Pavel Kovalyov
Pavel Kovalyov

Reputation: 1

try this:

$(document).on("click", "a[href*='#']", function(e){
    e.preventDefault();
    alert('works');
});

Upvotes: 0

Eric Lease
Eric Lease

Reputation: 4194

Correct your selector... href value should contain '#', not #

working fiddle

Upvotes: 1

Related Questions