5
I have the following code:
<select name='exemplo' id='exemplo'>
<option value='1' class='teste' dado='a'>1</option>
<option value='2' class='teste' dado='b'>4</option>
<option value='3' class='teste' dado='c'>3</option>
<option value='4' class='teste' dado='d'>2</option>
</select>
I know to catch the value
of option
selected can use:
$('#exemplo').change(function(){
var valor=$(this).val();
)};
But to get the attribute dado
? How do you do?
I recommend to use
.bind(
is better and not.change(
, for reason depends on jQuery version.$('#exemplo').bind('change', function() {
– KingRider
@Kingrider the
.change()
was added in version1.0
. The same as the.bind()
– Sergio
Perfect!! Thank you
– Amanda Lima
@Sergio, negative and nothing even, see about it, if the browser does not all work jquery function and follows (http://elijahmanor.com/differences-between-jquery-bind-vs-live-vs-delegate-vs-on/) ... that you put the pure javascript code very good,
option:checked
hum did not even know... good to know, thank you!– KingRider
@Kingrider is very useful, and already well supported: http://caniuse.com/#feat=css-sel3
– Sergio
@Kingrider I know that the
live
,on
,bind
anddelegate
are different, but here is the case ofchange
which was added along with thebind
in the version1.0
: https://api.jquery.com/category/version/1.0/– Sergio
Ual, this tip has helped me so much, thanks @Sergio
– adventistapr