javascript - js onclick function params -
How can I pass a feature of div in my own onclick function? For example, I have this div:
var join_button = document.createElement ("div"); Join_button.setAttribute ("category", "include_button"); Join_button.innerHTML = "contains"; Join_button.setAttribute ("room_name", name); Join_button.setAttribute ("onclick", "join_room ()");
Now, in the function join_room ()
I need to know this join_button's cell name
attribute. Of course, I do not have to Only one join_button
is on my page, I do not know that it is name
and I have to handle them all.
If I try to use this
tells me that has no undefined function
< Code> function join_room () {this.getAttribute ("room_name"); }
is not a undefined function
You can use this
to read the object attribute.
var join_room = function () {var room_name = this.getAttribute ('room_name); }
Then set onclick in this way.
join_button.onclick = join_room;
Comments
Post a Comment