Please tell me which libraries other than jQuery to traverse DOM.

Asked 2 years ago, Updated 2 years ago, 54 views

For now I know szarouski/lodash.dom-traverse. I would appreciate it if it was provided in npm.

A replacement has been found for the following features of jQuery:

QuerySelectorAllThe following methods in jQuery

can be used to obtain DOM elements that cannot be retrieved in a single shot.
  • parent()
  • prev()
  • children()

Retrieving using the .

Looking for a replacement library for these operations.

Also, since I use browserify, I am happy to be able to manage packages consistently if they are provided by npm.

javascript browserify

2022-09-30 11:57

4 Answers

Voyeur.js (http://adriancooney.github.io/voyeur.js/) or Dojo http://dojotoolkit.org/ (DOM module only).

Instead of a non-jQuery library (the new library is usually harder to learn than the new language...), what I want to do with raw js is:

var myDiv= document.getElementById('myDiv');
as=myDiv.querySelectorAll('ulia');
for (vari=0; i<as.length;i++)
    as[i].style.display='none';

Simple with recent browsers (foo.querySelectorAll: https://developer.mozilla.org/ja/docs/Web/API/document.querySelectorAll.


2022-09-30 11:57

I've never used it myself, but it's small and fast at 1.3k.https://github.com/KoryNunn/doc

However, document.querySelectorAll() may be enough for this purpose.In the past, JS did not own a query engine and went through the sizzle that jQuery contained, but now JS can use the query engine as a standard.

Note: I use cheeriojs/cheerio when I do DOM scraping on the server side.


2022-09-30 11:57

DOMtastic

Small, fast, and modular DOM&Event library for modern browsers. Same family API as jQuery (but without the extra "weight" of modules like $.ajax, $.animate, and $.Deferred). Weights in at only 3 to 14KB (minified), dependent on included modules. Full bundle is under 5KB gzipped.

It's also in npm, and it's like jQuery excludes heavy APIs.

Zepto

Zepto is a minimalist JavaScript library for modern browsers with early jQuery-compatible API.If you use jQuery, you already know how to use Zepto.

Compatible with jQuery.It is often introduced as for smartphones.

cash

Returning the $.

It's a little strange, but it's like jQuery.Less Traversal Module.

Voyeur.js

Voyeur is atiny (1.2kb) Javascript library that lets you traverse and manage the DOM the way it should have been. http://adriancooney.github.io/voyeur.js

This is not an API like jQuery, but you can use it as follows:

Voyeur.div.section.ul.li.eq(3).classList.add("Highlighted!");


2022-09-30 11:57

jsdom https://github.com/tmpvar/jsdom

After reading the question, the server will do a DOM operation to the jQuery-like
I feel like you're looking for a way to do it.

jsdom is a DOM implementation available in Node.js(orio.js) and
In conjunction with the DOM operating library running on the DOM of jQuery etc. You can use it.

Charlie Robbins "Scrapping with jsdom.js and jquery"
http://vwxyz.hateblo.jp/entry/20101014/1287047490


2022-09-30 11:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.