Reputation: 8239
Example current html code
<a rel="tag" title="see questions tagged 'php'" href="/tags/php/" class="tag-link-php">php</a>
I want use jQuery to replace it to be
<a href="http://php.net/"><img src="/images/tags/php.gif" height="16" width="16" alt="php" /></a><a rel="tag" title="see questions tagged 'php'" href="/tags/php/" class="tag-link-php">php</a>
Let me know
Upvotes: 0
Views: 307
Reputation: 235992
Looks like:
$("<a/>", {
"href": "http://www.php.net"
}).append($("<img>", {
"src": "/images/tags/php.gif",
"height": "16",
"width": "16",
"alt": "/images/tags/php.gif"
})).insertBefore(".tag-link-php");
Upvotes: 2
Reputation: 23051
Replace whole element / elements:
http://api.jquery.com/replaceWith/
Or just change some attributes:
Upvotes: 1
Reputation: 2001
You can also use replaceWith:
http://api.jquery.com/replaceWith/
Upvotes: 1
Reputation: 237855
So it seems to me that you want to put the following code
<a href="http://php.net/"><img src="/images/tags/php.gif" height="16" width="16" alt="php" /></a>
before any links with the class tag-link-php
. You can use the before
function for this:
$('a.tag-link-php').before('<a href="http://php.net/"><img src="/images/tags/php.gif" height="16" width="16" alt="php" /></a>');
Upvotes: 3