i am working with a project that require the use of php simple html dom parser, and i need a way to add a custom attribute to a number of elements based on class name.
i am able to loop through the elements with a foreach loop, and it would be easy to set a standard attribute such as href, but i can't find a way to add a custom attribute.
the closest i can guess is something like:
foreach($html -> find(".myelems") as $element) {
$element->myattr="customvalue";
}
but this doesn't work.
i have seen a number of other questions on similar topics, but they all suggest using an alternative method for parsing html (domdocument etc.). in my case this is not an option, as i must use simple html dom parser.
did you try it? try this example (sample: adding data tags).
output: