-1
var gethtml  = $("#topmenu > li.l89 a").text().split(' ')[1].replaceWith('Any World');

The text is not changing even after using replaceWith as shown above.

TRR
  • 1,637
  • 2
  • 26
  • 43
Dest
  • 678
  • 2
  • 9
  • 27

1 Answers1

0

After you call .text() you are no longer working with a jQuery object, but with a plain string. You can do it like this...

var text = $("#topmenu > li.l89 a").text()
  , textParts = text.split(' ');

textParts[1] = "Any world";
console.log('New text', textParts.join(" "));

I wrote the long version for you to see the steps. If you want you can do it on a single line, but it is not very readable anymore.

Split Your Infinity
  • 4,159
  • 1
  • 21
  • 19
  • yes but how i can now change $("#topmenu > li.l89 a") first word with textParts[1] ? – Dest Jul 06 '12 at 08:10
  • something like this should do it `$("#topmenu > li.l89 a").text(textParts.join(' ')​);​` – pms1969 Jul 06 '12 at 08:17
  • thanks i will choose other road like this : >>>>>>>>>> var first = $("#topmenu > li.l89 a").text().split(' ')[1]; var second = $("#topmenu > li.l89 a").text().split(' ')[2]; $("#topmenu > li.l89 a").html(""+first+" "+second); >>>>>> but your post is very good thanks :) – Dest Jul 06 '12 at 08:18