如何使用jquery在div中添加文本链接?

use*_*294 16 html javascript jquery href

我想在div中放置一些文本作为链接.

例如,我想在<a href="http://www.google.com"带有class-id为"my-link"的div中放置带有超链接的文本"Google ".

如何使用jquery或javascript完成?

Ser*_*gio 27

Class and ID is not the same.

If ID try this:

$('#my-link').html('<a href="http://www.google.com">Google</a>');
Run Code Online (Sandbox Code Playgroud)

Demo with ID

If Class try this:

$('.my-link').html('<a href="http://www.google.com">Google</a>');
   ^
Run Code Online (Sandbox Code Playgroud)

Demo with class