Search code examples
javascriptjqueryhtmlhref

how to add text link inside a div using jquery?


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?


Solution

  • 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