2011-01-18 54 views
0

例當前的HTML代碼這是可能使用jQuery,以取代現有的HTML代碼

<a rel="tag" title="see questions tagged 'php'" href="/tags/php/" class="tag-link-php">php</a> 

我想使用jQuery來代替它是

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

讓我知道

+1

你能澄清你問的是什麼?我看不出你到底想要做什麼,以及你想要的更普遍的轉換。 – templatetypedef 2011-01-18 23:18:36

+0

@templatetypedef 4人回答我的問題,這是一個問題:) – wow 2011-01-19 00:15:18

回答

3

所以它似乎我,你想把以下代碼

<a href="http://php.net/"><img src="/images/tags/php.gif" height="16" width="16" alt="php" /></a> 
在與類 tag-link-php有任何聯繫之前,請使用

。您可以使用before功能如下:

$('a.tag-link-php').before('<a href="http://php.net/"><img src="/images/tags/php.gif" height="16" width="16" alt="php" /></a>'); 
+0

謝謝寂寞天和工作完美! – wow 2011-01-19 00:14:13

2

的樣子:

$("<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"); 
相關問題