I've been trying to change an element ID using jquery for an A/B test.
From what ive seen, it should go something like this:
$('#tag').attr('oldId','newId');
But so far, no dice - any ideas?
*I've looked through the responses and i think i had the wrong end of the stick! I was assuming the current / old id had to be placed where ive labelled 'oldId', rather than id, followed by the replacement - silly mistake, thanks for all the help :)
Try to use the proper signature of .attr('attributeName','value'),
$('#tag').attr("id","newId")
Edited The right syntax is: $("#myId").attr("id", "mySecondId")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With