This question is in relation to a question I posted yesterday. The link -http://stackoverflow.com/questions/12636348/how-to-add-a-different-class-to-the-same-class-in-jquery . The question and problem now is that I will like to have a div added after the div with the class being added. The problem is the script that I’m using adds the div only to an existing/default class name and not the added class via JQuery. The script is below.
$(document).ready(function(){$('.example').each(function(i){$(this).addClass("ex" + i);});
$('.ex0').after(function(){return'<div class="afterdiv"><a class="afterdiva1" href="#" title="Text."></a><a class="afterdiva2" href="#" title="Text."></a></div>'});
The default output is:
<div class="example"></div>
The final html output should read as:
<div class="example ex0"></div>
<div class="afterdiv">
<a class="afterdiva1"></a>
<a class="afterdiva2"></a>
</div>
Update- I apologize for not clarifying that each div needs to be unique to/per class. Sincere apologies (I’m new to asking for help here or anywhere else for that matter).
You should put all these calls into the
.ready()function. Right now, the second line is executed before the DOM ready callback (because.ready()is an asynchrone function).