hi everyone it's my again. maybe its a stupid question but i can do it :>
I need to create a div object inside my xajax function. I do so
$response->create("parent id","The name of the new element","new id");
So far SO good. Next, i assign a property to my new object like this
$response->assign("new id","style.display","block")
again so far so good. My problem is when wanting to create a attribute. This is my code
$response->assign("new id","class","name of my class");
in html is something like <div id="p-new id" class="name of my class">
but i can't do this. Any suggestions are very good
Thanks.
Remember that ->assign(*id*, *prop*, *value*)
is translated into document.getElementById(*id*).*prop* = *value*;
Because class is a reserved word in Javascript, the class attribute is handled by the property className
.
So $response->assign("new id","className","name of my class");
will work.
Why don't you create whole object in one line like:
$response->assign("parent-id","innerHTML","<div id='p-new id' class='name of my class'>");
or if you can't change parent-id innerHTML create: firstly new-id div:
$response->create("parent-id","The name of the new element","new-id");
and then assign it's innerHTML new div:
$response->assign("parent-id","innerHTML","<div class='name of my class'></div>");
Unfortunatelly you will get structure
<div id="p-new id"> <class="name of my class"></div> </div>
not as you want
<div id="p-new id" class="name of my class"></div>
But you can adjust this idea to your needs and create sth like
<div id="outer-sth"><div id="p-new id" class="name of my class"></div></div>
Which I belive is close enough to what you are asking.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.