Danusorn Danusorn - 1 year ago 78
Javascript Question

jQuery get id from dropdown list not work

I need to get id from dropdown list but my code isn't work

$('.search-panel .dropdown-menu').find('a').click(function(e) {
var param = $(this).attr("href").replace("#","");
var concept = $(this).text();
$('.search-panel span#search_concept').text(concept);
$('.input-group #search_param').val(param);


Here is dropdown code

<ul class="dropdown-menu" role="menu">
<li id='1'><a href="#contains">น้อยมาก</a></li>
<li id='2'><a href="#its_equal">น้อย</a></li>
<li id='3'><a href="#greather_than">ปานกลาง </a></li>
<li id='4'><a href="#less_than">นิยม </a></li>
<li id='5'><a href="#all">นิยมมาก</a></li>

Answer Source

The <a> doesn't have an id, only the <li> has. Use:


Here, this refers to <a> and not the <li>.