jquery - Assign Id based on class -


i have html class name style1, style2 style.... , want assign id based on assigned class define in static html. want assign id in dynamic section. don't have access of dyanmic html want assign through jquery.

static class name section.

<div id="mediafarmplugin">   <div class="style1">get external content</div>   <div class="style2">get external content</div>   <div class="style3">get external content</div>   <div class="style4">get external content</div>   <div class="style...">......</div> </div> 

dynamic assign id based on class name style

<div id="table">   <div id="style1">style1 appear</div>   <div id="style2">style2 appear</div>   <div id="style3">style3 appear</div>   <div id="style...infinte number">style... infinate number appear</div> </div> 

please me

try this:-

 $(document).ready(function(){       $("div").each(function(){            if((this).attr('class') != undefined)                $(this).attr("id",$(this).attr("class"));       });    }); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -