Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I would like to append anchor text between a tags using jquery

I would like to append an anchor text in an a tag using jquery. Normally I can make an a tag look like this

<a href="#" >Hey</a> 

and Hey is the anchor text. But what I want to do is just have

<a href="#"></a>

and then use a javascript file running in the background append Hey as an anchor text to that link. How can I get that done?

EDIT This is what I tried to do but it didn't work.

$('hey').appendTo('.chat');

Where chat was the class name of the a tag.

$('<p>Hey</p>').appendTo('.chat');

That didn't work as well.

But thanks anyway guys. This code works

$('.chat').html('Hey');
like image 563
Michael Nana Avatar asked Sep 01 '25 21:09

Michael Nana


1 Answers

Seeing that you tagged jQuery in the question:

$('a').html('Hey');
like image 101
rink.attendant.6 Avatar answered Sep 03 '25 11:09

rink.attendant.6