0

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.

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
pradeep
  • 11
  • 1
  • 1
    That's used by jQuery internally. Why do you think you need to remove it? – Matt Ball Feb 23 '12 at 12:09
  • To answer part of the "Why do you think you need to remove it?" question, this dynamically generated attribute prevents highlighting/selecting contents contained within the bounds of the element to which it is implemented in IE browsers. The question should be, "Why does JQuery need to implement it in IE?" –  Jun 05 '12 at 18:07

3 Answers3

2

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.

Romain Paulus
  • 2,306
  • 1
  • 20
  • 20
0

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/

A.C.Balaji
  • 1,053
  • 4
  • 13
  • 23
-1

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);
Lawren Alex
  • 110
  • 5
  • we cannot find the exact attribute. that attribute will be dynamicly created , prefix with jquery – pradeep Feb 23 '12 at 12:15
  • we cannot define var id=1234567; this will be dynamic content – pradeep Feb 23 '12 at 12:16
  • What i exactly needed is to remove that particular attribute.Because it is dynamically generated in IE,but not in Firefox. – pradeep Feb 23 '12 at 12:21
  • lastAttrIndex=($("#sample")[0].attributes.length)-1; lastAttr=$("#sample")[0].attributes[lastAttrIndex].name; $("#sample").removeAttr(lastAttr); – Lawren Alex May 03 '12 at 09:13