function - How to get an element's value in jquery? -
how can value of data-toggle
inside function load_data(id)
? it's been messy lately. don't work whatever try.
<ul class="list-unstyled" id="faq_list"> <li data-type='parent'> <a href="javascript:;" data-toggle="a77" onclick="load_data(1)">general</a> <div id="target_1" class="subdata"></div> </li> <li data-type='parent'> <a href="javascript:;" data-toggle="b99" onclick="load_data(4)">orders</a> <div id="target_4" class="subdata"></div> </li> <li data-type='parent'> <a href="javascript:;" data-toggle="cab" onclick="load_data(3)">problems</a> <div id="target_3" class="subdata"></div> </li> </ul>
how can data-toggle
tag's value inside function load_data(id)
?
you can try solutions if want.
change :
<a href="javascript:;" data-toggle="a77" onclick="load_data(1)">general</a>
into
<a href="javascript:;" data-toggle="a77" onclick="load_data(1, this.attributes[1])">general</a> // this.attributes[1] --> capture element atribute @ index 1, // in case "data-toggle" // same goes element
javascript
function load_data(no, datatoggle){ console.log(datatoggle.value); }
===================== or =======================
change :
<a href="javascript:;" data-toggle="a77" onclick="load_data(1)">general</a>
into
<a href="javascript:;" data-toggle="a77" onclick="load_data(1, this)">general</a>
then in load_data function :
function load_data(no, elem){ console.log($(elem).data('toggle')); }
Comments
Post a Comment