1

I want to remove all attributes with name starting data-val-range.

I.e. from the following element I wanna remove the matching attributes:

<input data-val-range-min="*" data-val-range-max="$" data-val-range="hallelujah"/>

Is this possible?

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632

1 Answers1

2

Using this answer, You can just iterate through the attributes, and remove them according to the name...

Your javascript should be something like

$("input").each(function() {
  var theElem=this;
    $.each(this.attributes,function() { 
      if(this.specified) {     
        if(this.name.indexOf("data-val-range")>-1) {
          console.log("removing ",this.name);
          $(theElem).removeAttr(this.name); 
        }                                                     
      }
    })
});

Here is a jsfiddle https://jsfiddle.net/dkusds1s/

Community
  • 1
  • 1
ShaharB
  • 186
  • 8