Change ID to text in paragraph with jQuery

Posted by Reuben on Stack Overflow See other posts from Stack Overflow or by Reuben
Published on 2012-09-09T03:25:30Z Indexed on 2012/09/09 3:38 UTC
Read the original article Hit count: 291

Filed under:
|
|
|

I would like to take what text is in my p tag and make that the p tags parent (div) that ID. I would also like to add a _ for any spaces in the p tag.

Example:

<div class="circle"><p>Apple</p></div>
<div class="circle"><p>Banana</p></div>
<div class="circle"><p>Carrot Juice</p></div>

to

<div id="Apple" class="circle"><p>Apple</p></div>
<div id="Banana" class="circle"><p>Banana</p></div>
<div id="Carrot_Juice" class="circle"><p>Carrot Juice</p></div>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery