user1213684
user1213684

Reputation: 23

How to create anchor tag

$(".unfriend").click(function () {
    $(".friends_slected").text("Add Friend");
    return false;
});           

In this .text("Add Friend"); Add Friend text is added from this.... but how can we make this Add Friend an anchor tag not a simple text by using jQuery?

Upvotes: 2

Views: 4750

Answers (3)

abhinsit
abhinsit

Reputation: 3272

The html function takes an html string as input. So you just need to do:-

$(".friends_slected").html("<a href='anchor_url'>Add Friend</a>");

Hope that helps.

Upvotes: 1

TGH
TGH

Reputation: 39278

$(".unfriend").click(function () {
    $(".friends_slected").html("<a href='someurl'>Add Friend</a>");
    return false;
});

The .html method will let you add arbitrary html to your element

Upvotes: 4

Haim Evgi
Haim Evgi

Reputation: 125674

you can use wrap

$('.friends_slected').wrap('<a href="#" />');

Upvotes: 5

Related Questions