yoavf yoavf - 7 months ago 32
jQuery Question

Changing an element's ID with jQuery

I need to change an element's ID using jQuery.

Apparently these don't work:


I found out that I can make it happen with the following code:

jQuery(this).prev("li")show(function() {

But that doesn't seem right to me. There must be a better way, no? Also, in case there isn't, what other method can I use instead of show/hide or other effects? Obviously I don't want to show/hide or affect the element every time, just to change its ID.

(Yep, I'm a jQuery newbie.)


I can't use classes in this case, I must use IDs.


Your syntax is incorrect, you should pass the value as the second parameter: