Is it possible to access the Command Line Api from an external api?
Simple Example:
HTML
<div id="myDiv"></div>
<script src="myScript.js"></script>
myScript.js
$$('#myDiv').textContent = 'this will not work';
I do not wan't to load an external library like jQuery or Zepto because seens like this is already loaded locally.
To answer your question, no. But I don't think you really want to. The API may change, breaking your code. If all you're looking for is the query selector. I think you are better off using a snippet found on the MDN.
function $ (selector, el) {
if (!el) {el = document;}
return el.querySelector(selector);
}
function $$ (selector, el) {
if (!el) {el = document;}
return el.querySelectorAll(selector);
// Note: the returned object is a NodeList.
// If you'd like to convert it to a Array for convenience, use this instead:
// return Array.prototype.slice.call(el.querySelectorAll(selector));
}
alert($('#myID').id);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.