I'm currently don't know how to get the value of the class like the code i'm posting below. If i click the li class that has value of 0 i want it to do A If i click the li class that has value of 1 i want it to do B
I'm using bootstrap and jquery/javascript.
Sorry if my code seems not tidy, this is my first post , i'll try to tidy it up in the next posts.
I've been doing inspect elements and it's showed me no error, but the variable X isn't getting it's value from li.
Here it is i wanted it to do A if the selected is value 0
$(".clDropdown").click(function() {
debugger ;var x = document.getElementsByClassName("clDropdown").selectedIndex;
if (x == 0) {
alert("DO A");
debugger ;
} else if (x == 1) {
alert("DO B");
debugger ;
}
});
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
More <span class="caret"></span>
</button>
<ul class="dropdown-menu">//if 0 do A
<li class="clDropdown" value="0"><a href="#">Edit</a></li>
<li class="clDropdown" value="1"><a href="#">Delete</a></li>
</ul>
</div>
I expect that if i click the li that value 0 it'll do A , and if i click the li that has value 1 it'll do B