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

问题描述:

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

I want to place some text as link inside a div.

例如,我想在 class-id 为my-链接".

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".

如何使用 jquery 或 javascript 完成此操作?

How can this be done using jquery or javascript?

Class 和 ID 不一样.

Class and ID is not the same.

如果 ID 试试这个:

If ID try this:

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

演示 带 ID

如果班级试试这个:

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

演示 带类