php - Assigning Event handlers in DOM -
i creating element dynamically in php dom. able create element,create attributes wondering if can assign event handlers in this.
for example want assign onmouseover="function" element.then there way this?
$dom = new domdocument('1.0'); //create new document specified version number $a = $dom->createelement('a',$row['sname']); //create new tag $dom->appendchild($a); //add tag document $class = $dom->createattribute('class'); //create new attribute 'type' $class->value = 'button'; $a->appendchild($class); $href = $dom->createattribute('href'); //create new attribute 'type' $href->value = '#'; $a->appendchild($href);
and why don't add event same way add class attribute? onmouseover yet attribute.
$dom = new domdocument('1.0'); //create new document specified version number $a = $dom->createelement('a',$row['sname']); //create new tag $dom->appendchild($a); //add tag document $class = $dom->createattribute('class'); //create new attribute 'type' $class->value = 'button'; $a->appendchild($class); $event = $dom->createattribute('onmouseover'); //create new attribute 'type' $event->value = 'my function'; $a->appendchild($event); $href = $dom->createattribute('href'); //create new attribute 'type' $href->value = '#'; $a->appendchild($href); output:
<a class="button" onmouseover="my function" href="#">test</a>
Comments
Post a Comment