开发者

Extract value of userdefined attribute of a tag using jquery

开发者 https://www.devze.com 2022-12-12 09:18 出处:网络
I have input tags with a user defined attribute as:- <input name=\"grp1\" type=\"radio\" myUDF=\"value1\" />

I have input tags with a user defined attribute as:-

<input name="grp1" type="radio" myUDF="value1" />
<input name="grp1" type="radio" myUDF="value1" />开发者_开发百科;

How can i extract the value of myUDF?

The scenario is :-

$("input[name=grp1]").click(function(){
   this.attr("myUDF"); // This throws the exception Object doesnt support this prop or mehod
});


'this' is the dom object - not a jquery object therefore it does not have the attr function.

You need to create a jq object with this e.g

$(this).attr("myUDF");


you can get attribute value like that:

$("input[name=grp1]").click(function() {
    alert($(this).attr("myUDF"));
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号