admin管理员组文章数量:1026640
I would like to remove all the attributes that attribute name starts with 'data-val' in the fields that has a class 'read-only-state'
jQuery("[data-val^='tr']" )
This will give attribute 'data-val' value that starts with 'tr'
But i need to remove all the attributes that starts with 'data-val' in the matched elements.
How can i do it?
I would like to remove all the attributes that attribute name starts with 'data-val' in the fields that has a class 'read-only-state'
jQuery("[data-val^='tr']" )
This will give attribute 'data-val' value that starts with 'tr'
But i need to remove all the attributes that starts with 'data-val' in the matched elements.
How can i do it?
Share Improve this question edited Feb 6, 2013 at 14:58 Murali Murugesan asked Feb 6, 2013 at 14:27 Murali MurugesanMurali Murugesan 22.6k18 gold badges75 silver badges122 bronze badges1 Answer
Reset to default 7You can use vanilla javascript's attributes
for this:
$('.read-only-state').each(function() {
// get the native attributes object
var attrs = this.attributes;
var toRemove = [];
// cache the jquery object containing the element for better performance
var element = $(this);
// iterate the attributes
for (attr in attrs) {
if (typeof attrs[attr] === 'object' &&
typeof attrs[attr].name === 'string' &&
(/^data-val/).test(attrs[attr].name)) {
// Unfortunately, we can not call removeAttr directly in here, since it
// hurts the iteration.
toRemove.push(attrs[attr].name);
}
}
for (var i = 0; i < toRemove.length; i++) {
element.removeAttr(toRemove[i]);
}
});
I would like to remove all the attributes that attribute name starts with 'data-val' in the fields that has a class 'read-only-state'
jQuery("[data-val^='tr']" )
This will give attribute 'data-val' value that starts with 'tr'
But i need to remove all the attributes that starts with 'data-val' in the matched elements.
How can i do it?
I would like to remove all the attributes that attribute name starts with 'data-val' in the fields that has a class 'read-only-state'
jQuery("[data-val^='tr']" )
This will give attribute 'data-val' value that starts with 'tr'
But i need to remove all the attributes that starts with 'data-val' in the matched elements.
How can i do it?
Share Improve this question edited Feb 6, 2013 at 14:58 Murali Murugesan asked Feb 6, 2013 at 14:27 Murali MurugesanMurali Murugesan 22.6k18 gold badges75 silver badges122 bronze badges1 Answer
Reset to default 7You can use vanilla javascript's attributes
for this:
$('.read-only-state').each(function() {
// get the native attributes object
var attrs = this.attributes;
var toRemove = [];
// cache the jquery object containing the element for better performance
var element = $(this);
// iterate the attributes
for (attr in attrs) {
if (typeof attrs[attr] === 'object' &&
typeof attrs[attr].name === 'string' &&
(/^data-val/).test(attrs[attr].name)) {
// Unfortunately, we can not call removeAttr directly in here, since it
// hurts the iteration.
toRemove.push(attrs[attr].name);
}
}
for (var i = 0; i < toRemove.length; i++) {
element.removeAttr(toRemove[i]);
}
});
本文标签: javascriptHow to remove all Attributes by attribute name starts withStack Overflow
版权声明:本文标题:javascript - How to remove all Attributes by attribute name starts with - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745651189a2161329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论