I want to place some text as link inside a div.
For example, I want to place text 'Google' with hyperlink <a href="http://www.google.com" inside a div having class-id as "my-link".
How can this be done using jquery or javascript?
Class and ID is not the same.
If ID try this:
$('#my-link').html('<a href="http://www.google.com">Google</a>');
Demo with ID
If Class try this:
$('.my-link').html('<a href="http://www.google.com">Google</a>');
^
Demo with class
<script type="text/javascript"> document.getElementById('my-link').innerHTML = '<a href="http://www.google.com">Google</a>'; </script> but it didn't work. Also I am using class-name instead id as selector for div (although I changed my class-name as id in html while tried your solution.).If my-link is the class of the target div then
$('.my-link').html(function(idx, html){
return html.replace(/Google/g, '<a href="http://www.google.com">Google</a>')
})
Demo: Fiddle