0

I'm working a framework that create on screen certain elements that should not be modified in any way, at all, ever, under any circumstances . These elements always have a data-for attribute with some value.

I know I could exclude them from a selector by using not command like:

 input:not([data-for], .exclude)

In case of having a value I know I could do something like

input:not([data-for=lalala], .exclude)

The problem is that I won't know the value at development time and the first option only works when the attribute has no value. Is there another to do this?

Anurag Srivastava
  • 14,077
  • 4
  • 33
  • 43
Paulo Künzel
  • 729
  • 2
  • 7
  • 30

1 Answers1

2

The input:not[data-for] selector should work. See below:

$(document).ready(function(){
  console.log($('input[data-for]').length);
  console.log($('input:not([data-for])').length);
});
input{ display: block; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input data-for="" />
<input data-for="something" />
<input />
<input />
<input data-for="something" />
<input data-for="" />
Anurag Srivastava
  • 14,077
  • 4
  • 33
  • 43
  • It should work, for some reason it does not. I'm gonna test again tomorrow when I get back to work. Maybe it is something I missed. – Paulo Künzel Apr 20 '20 at 20:05
  • After a lot of checking I've found out that the framework had other hidden inputs which shouldn't be changed. So the data-for is only part of the issue. I'm going to mark your anwser as correct because it does solve the problem that I've posted, even though, unfortunately, it doesn't solve my problem :(. Thanks anyways for the help. – Paulo Künzel Apr 24 '20 at 12:05
  • @PauloKünzel No problem, and post again if you have issues – Anurag Srivastava Apr 24 '20 at 14:36