admin管理员组文章数量:1321056
Using Prototype JS library, I want to select all child link elements (A tags) regardless of whether their parent is: H1, H2, H3, H4, or H5 (etc) with a simple CSS Selector Rule (as opposed to further JS, like looping etc).
So the simple, but long way, to do this is:
$('page').select('h1 > a, h2 > a, h3 > a, h4 > a, h5 > a')
I guess I'm looking for a wild-card property, like h*, that doesn't exist.
Maybe the above example is the way to go, but I'm hoping there is a simpler, more concise and efficient way to do this.
Tips appreciated.
Using Prototype JS library, I want to select all child link elements (A tags) regardless of whether their parent is: H1, H2, H3, H4, or H5 (etc) with a simple CSS Selector Rule (as opposed to further JS, like looping etc).
So the simple, but long way, to do this is:
$('page').select('h1 > a, h2 > a, h3 > a, h4 > a, h5 > a')
I guess I'm looking for a wild-card property, like h*, that doesn't exist.
Maybe the above example is the way to go, but I'm hoping there is a simpler, more concise and efficient way to do this.
Tips appreciated.
Share Improve this question edited Dec 29, 2011 at 16:38 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Oct 22, 2009 at 19:57 donohoedonohoe 14.1k4 gold badges39 silver badges61 bronze badges 1- 4 I think this is the way to go, as there isn't an infinite number of heading tags, only 5 – Fabien Ménager Commented Oct 22, 2009 at 20:22
4 Answers
Reset to default 4As per Fabien Ménager ment to the original question, it looks like there isn't a simple CSS Selector I can use other than what I have already.
$('page').select('h1 > a, h2 > a, h3 > a, h4 > a, h5 > a')
While there are other options if I want to be programmatic about it, or empty JQuery (which isn't an option for me) I am specifically looking for a CSS rule.
Thank you to everyone who tried to help.
Using jQuery:
$(":header a")
http://docs.jquery./Selectors/header says:
:header Matches all elements that are headers, like h1, h2, h3 and so on.
Adds a background and text color to all the headers on the page.
$(":header").css({ background:'#CCC', color:'blue' });
got an answer to this from the prototype devs. these are best and only solutions, for now at least:
$$('h1 > a, h2 > a, h3 > a, h4 > a, h5 > a, h6 > a')
$('page').select('h1 > a, h2 > a, h3 > a, h4 > a, h5 > a')
However, the next release of Prototype will let you choose a selector engine and will default to Sizzle. The :header
pseudo-selector is actually part of Sizzle so will be available in future versions of prototype (as long as you choose sizzle as your selector engine). I guess it was not previously included as it is not part of any specification.
本文标签: prototypejsCSS Selectors in Javascript with all H tagsStack Overflow
版权声明:本文标题:prototypejs - CSS Selectors in Javascript with all H tags - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742092893a2420373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论