تحصل jQuery على نص بمحتويات أحرف البدل بعد العنصر وتحريكه
سؤال
أعتقد أن هذا قد يكون أمرًا صعبًا، ولكن إذا تمكن أي شخص من حله سأكون منبهرًا جدًا، وأيضًا ممتنًا جدًا.
وهنا العلامات الموجودة (وهو ما لا أستطيع تغييره، وإلا ستكون مشكلة سهلة ويمكنني حلها بنفسي!):
<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)
ما أريد فعله هو التقاط الأقواس والقيمة الموجودة بداخلها ([WILDCARD VALUE HERE])، وقصها وإلحاقها داخل العلامات <a > المغلفة في <span>.
إذن هذا ما أسعى إليه:
<a title="1 topics" href="http://localhost/tags/amis/">amis <span>(1)</span></a>
مرة أخرى، إذا كان أي شخص لديه أي أفكار ...شكرًا!
المحلول
جرب هذا
$('a').each( function(){
var $this = $(this);
var textEl = this.nextSibling;
var spanEl = $('<span />').text(textEl.data);
$this.append( spanEl );
$(textEl).remove();
});
لا تنتمي إلى StackOverflow