Send to a Friend

klaas4's avatar

How to mimic jQquery's appendTo with a regular expression?

Asked by klaas4 (2189points) July 8th, 2011

Hi!

I use WordPress to manage a website and I’m currently (still… :) ) developing a theme. Now, I wrap some content in a div with a specific class to box it, but I want to append a clear:both-div to that div in case there are any floating elements. I use jQuery as a temporary solution, like so:

$(’.block’).append(’<div class=“clearboth”></div>’);

I figure this can also be done with another way. Problem is, I have no clue how I’d go about something like this. Can I use any WordPress functions or would a regex be appropriate here?

I think it has to go something like this.

• Find all <div> start tags ”<div ”
• Find class=” or class=’
• Look for the class name (e.g. ”block”) before or .
• Then append the clear:both-div just before the corresponding </div> tag.

I hope someone can help.

Thanks!

Davey

Using Fluther

or

Using Email

Separate multiple emails with commas.
We’ll only use these emails for this message.