tags:

views:

17

answers:

2

Is it possible to get and place content within an html tag by its class name? For Example:

<div class='edit'>
Wow! I'm the Content.
</div>

Is it possible to get that value, edit and place it back or a new value to that div etc? If it's possible... will it work if it has multiple classes? Like:

<div class='span-20 edit'>
Wow! I'm the Content.
</div>
+1  A: 

If you can determine which specific HTML tag to manipulate, you have various tools at your disposal. You can use str_replace, preg_replace, DOMDocument, DOMXPath, and simplexml in this situation.

stillstanding
+1  A: 

If in PHP, try this:

$xhtml = simplexml_load_string("<div class='edit'>Wow! I'm the Content.</div>");
$divs = $xhtml->xpath('//div[@class=edit]');
if (!empty($divs){
    foreach ($divs as $div){
        $div['class'] .= ' span-20';
    }
}
return $xhtml->asXML();

With jQuery javascript library, do this:

$('.edit').addClass('span-20');
Tim