Using argument (this) passed via element eventhandler
Posted
by Kel
on Stack Overflow
See other posts from Stack Overflow
or by Kel
Published on 2010-05-18T14:44:40Z
Indexed on
2010/05/18
15:01 UTC
Read the original article
Hit count: 345
Hey guys,
I want to use the argument I pass (this) in a JS function and treat it as an jQuery variable. Example:
<script>
function useMe(obj){
$(obj).val();
...
...
...
}
</script>
<select id="selectid" onChange="useMe(this)">
<option>......</option>
</select>
Is there a possibility to treat the passed argument as a jQuery element?
Btw. I need to do it this way, because the select-element isn't created on load. The select element will be created later asynchronously.
So, this won't work:
$("select").each(function (i){
var select_id = $(this).attr("id");
$(this).change(function(e){
because it doesn't exist yet.
Thanks for your help.
© Stack Overflow or respective owner