开发者

What methods are present to select elements in chrome extensions?

I know about getElementById, getElementByNames ... and getElementsByTagName

What other methods are available to select an element or elements from the DOM ? What if an item does not have an Id or Name.

I have heard that I can use XPath expressio开发者_Python百科n to select a range of HTML elements. How do i do that using JavaScript? Is there a library that will help me achieve this?

Thanx a lot in advance :)


Why not just use jQuery?

If you need it in scripts you can inject jquery.js through manifest.json:

"content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "js": ["jquery.js", "myscript.js"]
    }
  ]

If you need it in html pages (background, options etc) you can use

<script src="jquery.js"></script>

or even

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜