tags:

views:

71

answers:

3

Hi, I have this code which I am trying to change the ID of on.hover.

<span id="slidingProd">
    <a href="{link controller=order action=addToCart id=$product.ID returnPath=true}" rel="nofollow" class="addToCart" title="Bestill"
     onclick="addToBasket(); return false;" id="fly_to_basket">&nbsp;</a>
</span>

I tried to use this jQuery, but it doesn't change the ID.

$(function() {
    $("#fly_to_basket").hover(function() {
      $(this).parent().attr("id",slidingprod(1));

});
    $("#fly_to_basket").hover(function() {
      $(this).attr("onclick",addToBasket(1));
});

What am I doing wrong?

Thanks :)

+2  A: 

$(this)..... Not $("this")

E Rolnicki
Duh.. Thanks, that's one problem I guess but it still doesn't change the ID.
Kyle Sevenoaks
A: 

Does $("this") work with quotes? I think $(this) is better.

Anyway, I don't like changing ID's at runtime. Seems messy...

Koen
+2  A: 

Going by your comment

I just need to change the id from slidingprod to slidingprod(1)

  1. Brackets aren't valid characters for ID strings. http://www.w3.org/TR/html401/types.html#type-name:

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

  2. You haven't enclosed the new ID in a string.

ex:

$(this).parent().attr("id","slidingprod-1");
Andy E
I thought this might be it... If you don't enclose the new ID in a string then it's parsed as JavaScript, and `slidingprod(1)` in JavaScript means "call the slidingprod() function with an argument of 1".
Skilldrick
I think that this solution won't work then if I can't use brackets as a simple replace as `Botondus` said. Thanks for cleaning up my jQuery code. I don'y know how to implement this then.
Kyle Sevenoaks