remove a PART of an Anchor Text with jquery or javascript -


i'm trying remove or change part of anchor text.

my anchor this:

<a href="http://something.com">model 1234 motorbike</a> 

i remove "motorbike" part of anchor text, end with:

<a href="http://something.com">model 1234</a> 

anyone know how this?

thanks

update:

the anchor links coming different website. can't control html. i'm trying remove "motorbike" part anchors sent, doesn't show 100 times on webpage.

@shiv kumar: yes, "motorbike" last part of anchor text. @phrogz: script sending available models site. last part of anchor text "motorbike", first part changes: model 1234, type 4321 etc.

but give codes try first.

thanks quick replies.

much appreciated.

erik

a) modify html sent browser, don't try patch on client. if user has javascript turned off?

b)

// rid of last word in text anchors referencing // domain something.com $('a[href*="something.com"]').html(function(oldhtml){   return oldhtml.replace(/\s\s+$/,''); });  // keep "model xxxx" $('a[href*="something.com"]').html(function(oldhtml){   return oldhtml.replace( /^(model \d+).+/, '$1' ); }); 

edit: remove word 'motorbike' every link:

$('a').html(function(oldhtml){   return oldhtml.replace( ' motorbike', '' ); }); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -