I have one element "<a id="sample" jquery1234567="0">Testing</a>"
I want to remove the last attribute (jquery1234567) from the above tag. But the attribute "jquery1234567" will be generated dynamically.
I have one element "<a id="sample" jquery1234567="0">Testing</a>"
I want to remove the last attribute (jquery1234567) from the above tag. But the attribute "jquery1234567" will be generated dynamically.
The value of this generated attribute is $.expando
. So if you want to remove it, simply use:
$('#sample').removeAttr($.expando);
Although I wouldn't recommend removing this attribute, because it is used by jQuery to keep track of the event handlers bound to DOM elements. The proper way to affect this behavior would be to unbind events from this element with jQuery.
try this
$.fn.getRegexAttr = function(regex, action) {
if( !this.length ) return false;
if( 'remove' == action ){
var that = this;
$(this[0].attributes)
.filter(function(){ return regex.test(this.name); })
.each(function(){ $(that).removeAttr(this.name); });
}else if( 'fetch' == action ){
return $(this[0].attributes)
.filter(function(){ return regex.test(this.name); })
.map(function(){ return $.trim(this.name); })
.get();
}
}
if( $('#sample').getRegexAttr(/jquery[0-9]/, 'fetch') )
alert( $('#sample').getRegexAttr(/jquery[0-9]/, 'fetch').join(',') );// To get the matched attributes
$('#sample').getRegexAttr(/jquery[0-9]/, 'remove');// To remove the matched attributes
you can also verify in : http://jsfiddle.net/Nng8n/3/
try this
$("#sample").removeAttr('jquery1234567');
(or)
var id=1234567;
$("#sample").removeAttr('jquery'+id);
this is not help for you..Pls add some extra description with code...
Hi friend this will help you
lastAttrIndex=($("#sample")[0].attributes.length)-1;
lastAttr=$("#sample")[0].attributes[lastAttrIndex].name;
$("#sample").removeAttr(lastAttr);