2009-08-02 8 views
2

Ich denke, das könnte ein heikles sein, aber wenn jemand es lösen kann, wäre ich sehr beeindruckt und auch sehr dankbar.jQuery Text mit Wildcard-Inhalt nach einem Element und verschieben Sie es

Hier ist die bestehende Markup (die ich nicht ändern kann, sonst dann würde es ein leichtes Problem sein, und ich kann es selbst lösen!):

<a title="1 topics" href="http://localhost/tags/amis/">amis</a> (1) 
<a title="2 topics" href="http://localhost/tags/amis/">amis</a> (2) 
<a title="1 topics" href="http://localhost/tags/amis/">amis</a> (1) 
<a title="3 topics" href="http://localhost/tags/amis/">amis</a> (3) 

Was ich will, zu tun ist, Nimm die Klammern und den Wert darin ([WILDCARD VALUE HIER]), schneide ihn und klebe ihn in die < a> Tags, die in eine < Spanne verpackt sind.

So ist das, was ich nach:

<a title="1 topics" href="http://localhost/tags/amis/">amis <span>(1)</span></a> 

Noch einmal, wenn jemand eine Idee hat ... Danke!

Antwort

3

dieses Sir

Demo here

$('a').each(function(){ 

    var $this = $(this); 
    var textEl = this.nextSibling; 
    var spanEl = $('<span />').text(textEl.data); 
    $this.append(spanEl); 
    $(textEl).remove(); 

}); 
+0

Sie versuchen, sind ein Genie. Danke für Ihre Hilfe. :) – davebowker

+0

Keine Sorge, viel Glück. – redsquare