Ahmad Usama Beg
Ahmad Usama Beg

Reputation: 325

Assign dynamically a link in a Div

we have a way to select a div and assign a text to it like as follows.

$(#divID).text("some text to show").

I want to put a hyperlink dynamically in the text to be shown in div. I mean the URL of the link will be passed from a method. Anyway to do it.

Thanks in Advance,

Upvotes: 0

Views: 131

Answers (2)

Neeraj
Neeraj

Reputation: 1816

You can append the link as html in the div like below

$("#divId").html("<a href='url'>hyperlink</a>")

it should work on all browsers.

Upvotes: 0

sdespont
sdespont

Reputation: 14025

Try like this :

$('#divID').html("<a href='www.go.com/mypage.php'>some text to show</a>").

or append to the existing content

$('#divID').append("<a href='www.go.com/mypage.php'>some text to show</a>").

Upvotes: 2

Related Questions