DOM元素查找高亮庫:highlighter.js

jopen 10年前發布 | 37K 次閱讀 JavaScript開發工具包 highlighter.js

Highlighter.js是一個迷你純JavaScript庫,能夠讓輕松查找,選擇和高亮DOM元素。

document.addEventListener("DOMContentLoaded", function() { 
  var Highlighter = new window.Highlighter();

  Highlighter.next('<div>');
  Highlighter.underline(); window.console.log('Highlighter underlined this element:', Highlighter.element);
});

Demo

Live demo

Commands

Select Next

Select next element starting from the current selected element (by default is the first DOM element)

Highlighter.next();

Select Previous

Select previous element starting from the current selected element ( by default is the first DOM element)

Highlighter.previous();

Skip Next

Skip a bunch of next elements starting from the current selected element

Highlighter.skipNext(50);

Skip Previous

Skip a bunch of previous elements starting from the current selected element

Highlighter.skipPrev(35);

Underline

Highlight the current selected element

Highlighter.underline();

Erase

Remove highlighting from the current selected element

Highlighter.erase();

Select Next by ID

Select next element (by ID) starting from the current selected element (by default is the first DOM element)

Highlighter.next('#test');

Select Next by class/es

Select next element (by class/classes) starting from the current selected element (by default is the first DOM element)

Highlighter.next('.class .class-2');

Select Next by < tag > name

Select next element (by < tag > name) starting from the current selected element (by default is the first DOM element)

Highlighter.next('<span>');

Select Previous by ID

Select previous element (by ID) starting from the current selected element (by default is the first DOM element)

Highlighter.previous('#test');

Select Previous by class/es

Select previous element (by class/classes) starting from the current selected element (by default is the first DOM element)

Highlighter.previous('.class .class-2');

Select Previous by < tag > name

Select previous element (by < tag > name) starting from the current selected element (by default is the first DOM element)

Highlighter.previous('<span>');

Select Element By ID

Select first element in the DOM by ID

Highlighter.select('#id');

Select Element by class/es

Select first element in the DOM by class or classes

Highlighter.select('.class .class2');

Select Element by tag name

Select first element in the DOM by < tag > name

Highlighter.select('<span>');

項目主頁:http://www.baiduhome.net/lib/view/home/1438503379920

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!