I’m using Zend_DOM_Query to read HTML elements using DOM.
<input type="text" class="a">
<input type="text" class="a">
<input type="text" class="a">
I load the html and find the <input> and then loop through the results.
foreach($inputss as $input){
}
What I actually want to do is add additional markup after each <input> like another input but of different class name <input type="text" class="b">. At the end my full markup will look like this
<input type="text" class="a">
<input type="text" class="b">
<input type="text" class="a">
<input type="text" class="b">
<input type="text" class="a">
<input type="text" class="b">
I keep seeing examples that use createElement() but nothing that seems to add HTML the way I need it added. Am I missing something?
The easiest way to do this is indeed with
createElement:Apart from the last line, which is admittedly a little verbose, this seems quite simple to me.
I suppose you could do this with
createDocumentFragmentand useappendXMLto insert a string of HTML, but I don’t see that that would be significantly easier or quicker.NB that the reason this works is that within a
Zend_Dom_Query_Resultobject are normal DOM objects, so you can use normal DOM methods on them.