-1

I have this jQuery selector:

$('#stuffElements').find('[data-markerlayer="layer1"]');

I have a ton of selectors similar to this one, and I want to optimize my script as much as possible, as rewriting most selectors requires only minimal effort on my part.

Disregarding the discussion whether this is useful, is it possible to write the above selector out in pure JavaScript?

yesman
  • 7,165
  • 15
  • 52
  • 117

1 Answers1

0
document.querySelectorAll('#stuffElements [data-markerlayer="layer1"]')

or to make it more efficient:

var holder = document.getElementById('#stuffElements'); // cache parent node
holder.querySelectorAll('[data-markerlayer="layer1"]'); // finds inside it

querySelectorAll doesn't work in IE7 if that bothers you.

Spadar Shut
  • 15,111
  • 5
  • 47
  • 54
  • 2
    Don't just dump an solution into the answer. Give it a bit of an explanation. Pro's and cons of using the method, why you chose a certain approach, why something is "more efficient", stuff like that. Or better yet, vote as duplicate./ – Cerbrus Nov 21 '14 at 09:20