Zeb-ur-Rehman
Zeb-ur-Rehman

Reputation: 1209

CSS appendTo("");

$(document).ready(function(){$("[href]").appendTo(" Click here ...");});

HTML Code

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

I want to to show it on browser as b Click here ... But i didn't work properly here.

Upvotes: 1

Views: 1147

Answers (6)

4b0
4b0

Reputation: 22323

Use ID insted of tag.If you have multiple anchor tag its work for all.

    $(document).ready(function(){
    $("#YourID").append(" Click here ...");
    });


 <a href="#" id="YourID"> b </a>

Upvotes: 0

gherkins
gherkins

Reputation: 14983

have you tried append instead of appendTo ?

$(document).ready(function(){$("[href]").append(" Click here ...");});

from my understanding it works like:

element.append('stuff to append to the element');

vs

element.appendTo(otherElement);

Upvotes: 1

Nishu Tayal
Nishu Tayal

Reputation: 20860

Try this.

$(document).ready(function(){
  $("[href]").append(" Click here ...");
});​

Use .append() function instead of .appendTo() function.

Here is the demo

Upvotes: 1

Andrew
Andrew

Reputation: 2164

I think you are looking for append() rather than appendTo().

append() simply takes the text or jQuery element that you supply as an argument and appends it as the last child of the element that you have selected - I think this is the behavious you are looking for. The documentation for append() is at http://api.jquery.com/append/ if you want to look into it more.

Upvotes: 0

Blaster
Blaster

Reputation: 9080

Change:

$("[href]").appendTo(" Click here ...");

To:

$("[href]").html(" Click here ...");

With appendTo, you are supposed to add a new DOM element not text node.

Upvotes: 0

Govind Malviya
Govind Malviya

Reputation: 13753

Use direct tag selector and also append method

$(document).ready(function(){

            $("a").append(" Click here ...");

    });

Upvotes: 1

Related Questions