Cheetah
Cheetah

Reputation: 137

jQuery Clone and renaming child elements

I have a DIV Element with an image, some text, a url link to the image and a link to a status of the image

This status link has a class that uses a csshook, meaning that the image ID is part of the class name(statusrec41).

Using jQuery I clone the DIV.

$clone =  $('#divrec41').clone(true).attr('id', '#divrec42');

I then update the URL with the new record ID

$clone.find('[href]').each(function(){this.href=this.href.replace(/rec41/g, 'rec42')})

Then display at end

$clone.appendTo('#imageArea');

The part I am lost in is in how to update the class name to reflect the new ID before I append the cloned element Would be nice if I could do a replace all "rec41" to "rec42", but noooo

Upvotes: 0

Views: 385

Answers (2)

Edward
Edward

Reputation: 1914

you can do it in one line:

$clone.attr('class', your_classes).appendTo('#imageArea');

Upvotes: 1

pyb
pyb

Reputation: 5269

Can you do this ?

$(document).find('.rec41').each(function(){
    $(this).removeClass("rec41");
    $(this).addClass("rec42");
})

Upvotes: 0

Related Questions