Reputation: 2428
inside my HTML page I add some text using this:
<script>
$('.description').text('my description')
</script>
Inside my description
I need to place an anchor tag href to an external link like this: <a href="http://link_to_website.com">link to a website</a>
How could I proceed using jQuery to achieve something like this?
Upvotes: 0
Views: 44
Reputation: 6031
use .html()
$('.description').html('<a href="http://link_to_website.com">link to a website</a>')
or
$('.description').html('my description <br> <a href="http://link_to_website.com">link to a website</a>')
Upvotes: 1
Reputation: 74738
You might need to do this:
$('.description').text('my description').append($('<a />', {href:"http://linkofhref", text:"text goes here."}));
Check the demo below:
$('.description').text('my description ').append($('<a />', {href:"http://linkofhref", text:"text goes here."}));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='description'></div>
Upvotes: 3
Reputation: 2353
try this..
<script>
$(document).ready(function(){
$('.description').html('<a href="http://link_to_website.com">link to a website</a>');
});
</script>
Upvotes: 1