tags:

views:

36

answers:

1

I have the following code on the my page...

<a href="javascript:change_product_photo(2);"><img id="alternate_product_photo_2"    style="border-color:#666666;" src="/v/vspfiles/photos/00-6189-2S.jpg" border="1">

Sometimes there could be more of the <a href="javascript:change_product_photo(4);"> and each one would have a higher index number 5, 6 ,7, etc.

What I want to do is for each and every instance of the href with javascript:change_product_photo(x) (where x is the index) remove both "_" from the change_product_link but leave the (x) index

My thought was to first add a class to all hrefs that contain javascript:change_product_photo and then modify all of the href;s with that class but I am lost on how to do this.

Here is what I got so far...

$("a[href*='javascript:change_product_photo']").addClass('link_fix');

Now I don't know how to remove the "_" from the url.

+1  A: 

try...

$("a[href^='javascript:change_product_photo']")
    .addClass('link_fix')
    .attr('href', function(i,v){
        return v.replace('_','');
    })

edit based on comment, note the href*= has changed to href^= (start-with selector)

and read 'Easy Setter Functions' function(i,v){...} as of jQuery 1.4.x

Reigel
Wow that was fast and it worked great, thanks so much. I realize this is not really the place to go into detail but I don't understand the function(i,v), can you explain it?
Sorry I spoke too soon. it doesn't work.Below is the code that works but no clean If I had more links I has to make add more code manually$("a[href*='javascript:change_product_photo(2)']").addClass('link_fix2');$("a[href*='javascript:change_product_photo(3)']").addClass('link_fix3');$("a[href*='javascript:change_product_photo(4)']").addClass('link_fix4');$("a.link_fix2").attr('href', 'javascript:change_product_photo_fix(2)');$("a.link_fix3").attr('href', 'javascript:change_product_photo_fix(3)');$("a.link_fix4").attr('href', 'javascript:change_product_photo_fix(4)');
please see my edits...
Reigel
That was great and I verified that it does work. The href*= was not he issue it was the fact that I had an older version of jquery lib 1.3.2 and when you gave me the reason link to the function(i,v) statement it all cam together, LOL thanks
good!... glad it was solved.. ;)
Reigel