php - Accesing the id attribute of the select tag from jquery -


i looking way access id attribute of select tag jquery.

say have select tag on form : form.php

<select id="testid"> <option value="1">1</option> <option value="2">2</option> </select> 

from jquery can access option value $(this).attr("value"). $(this).attr("id") gets undefined.

by giving option tag id attribute values works. but, there way around access id of select tag thru $(this) object

thanks help

if trying within change event of select like:

$('select').change(function() {      // here 'this' point select     console.log( $(this)[0].id );     //or     console.log(this.id);  }) 

but $(this).attr('id') should work.

if $(this) point option try

$('select').has(this).attr('id'); 

or

$(this).parent('select').attr('id'); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -