Example in jquery
You check if there is an attribute on an element in jQuery. The below is the example for checking whether the tag has attribute in jquery or not..var attr = $(this).attr('name');
// For some browsers, `attr` is undefined; for others,
// `attr` is false. Check for both.
if (typeof attr !== typeof undefined && attr !== false) {
// ...
}
Example
$(document).on('click','body',function(){
var uid = $('.user-id').attr('readonly');
if(typeof uid !== typeof undefined && uid !== false);
else $('.user-id').attr('readonly','readonly');
});
Html
<input type="text" class="user-id" required readonly="readonly" value="12" title="User id cannot be changed" />
0 comments:
Post a Comment