To not do so:

$('*') 

Is there any way to do this so that only elements that have the data- attribute (for example data-test, data-bla) are taken:

 $('[data-*]') 

?

  • No, you can not do there. But you can use filter - Grundy
  • if this is the continuation of the question of how angular work - then you are going in the wrong direction. - Grundy
  • @Grundy on Jquery writing mini framework - bsbak
  • very similar to the XY-problem - most likely the main problem is something else. For example the wrong design of the mini framework - Grundy

1 answer 1

 $("*").filter(function(){ var attributes = this.attributes; for (var i = 0; i < attributes.length; i++) { if (attributes[i].name.indexOf("data-")==0) return true; } return false; }); 

Here it is possible.

  • the author wants to check the entire document - Grundy
  • Corrected to search for everything) - Moonvvell
  • MDE =) So it has already been written to me, as it would be easier and faster to work something =) - bsbak
  • @bsbak, obviously you need to limit the set of elements to apply. This can be done in two ways: 1. narrow the search area from the entire document to a specific container. 2. search not all possible data attributes, but only the specified ones. You can use two approaches at once. - Grundy
  • one
    @bsbak, and here you are mistaken. If you look at it, the constructor is called here $ (this) , the function is being called, which is not very simple, and the same loop inside isEmptyObject , albeit from a single iteration. instead of this line is better: $.isEmptyObject(this.dataset) - Grundy