Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: add html after a group of divs

Tags:

jquery

I have something like this: ...

<div id="d120" >content</div>
<div id="d123" >content</div>
<div id="d112" >content</div>
<div id="d145" >content</div>
<div id="d134" >content</div>
//Insert here hello world

<div id="bla" >asd</div>
<div id="footer" >asd</div>

anybody knows how to insert html after all the divs that have id like d+number

like image 750
Omu Avatar asked May 11 '10 12:05

Omu


1 Answers

If the format doesn't have anything between those divs and #bla like your example, here's a safer approach using .before() (since div[id^=d] would match <div id="doodlesticks"> as well).

$("#bla").before("<b>Hi There</b>");

Update: Since you said it's possible to give them a class, I'd do that, so give the content divs a class="content" and use this jQuery:

$(".content:last").after("<b>Hi There</b>");
like image 105
Nick Craver Avatar answered Sep 17 '22 15:09

Nick Craver