Reputation: 189
Hi I'm working on inserting a text to this DOM but my try did not work like I expecting.
<p class="doing">Peter are <a href="mysite.com">here</a></p>
<script>$("p.doing").before("I and ");</script>
I'm expecting to have result:
<p class="doing">I and Peter are <a href="mysite.com">here</a></p>
but it was :
I and
<p class="doing">Peter are <a href="mysite.com">here</a></p>
Please kindly advise how to solve this.
Upvotes: 0
Views: 82
Reputation: 5640
instead of before, you should use prepend, as before will insert the text into p tag with a class doing.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p class="doing">Peter are <a href="mysite.com">here</a></p>
<script>$(".doing").prepend("I and");</script>
</body>
</html>
Upvotes: 0
Reputation: 1533
Use the jQuery prepend() method:
<p class="doing">Peter are <a href="mysite.com">here</a></p>
<script>$(".doing").prepend("I and ");</script>
Upvotes: 0