Skip to content Skip to sidebar Skip to footer

Jquery Select When Attribute Name Starting With?

I want to remove all attributes with name starting data-val-range. I.e. from the following element I wanna remove the matching attributes:

Solution 1:

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/

Post a Comment for "Jquery Select When Attribute Name Starting With?"