473,387 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

script that returns elements matching css selectors

Anyone know of a script which returns a list of elements matching a
specified CSS selector?

Kae
Jul 23 '05 #1
2 1223
Kae Verens wrote:
Anyone know of a script which returns a list of elements matching a
specified CSS selector?


hehe! I was thinking exactly of how Dean Edwards' IE7 script selects
elements, and low and behold, the man himself has exactly the script I need
- cssQuery().

Thanks anyway.

kae
Jul 23 '05 #2
Kae Verens wrote:
Kae Verens wrote:

Anyone know of a script which returns a list of elements matching a
specified CSS selector?

hehe! I was thinking exactly of how Dean Edwards' IE7 script selects
elements, and low and behold, the man himself has exactly the script I need
- cssQuery().

Thanks anyway.

kae

You may like Dean's script, but if your needs are simpler, here
is a script that returns all the elements with a certain class
name, even if an element has multiple class names. To make it
faster, pass a start element so search below (it currently
starts at body) to reduce the scope of the recursion.

It returns an array of the matched objects:
function getElementsByClassName(c) {
var cArray = [];
var n = document.getElementsByTagName('body')[0];
var z = new RegExp('\\b' + c + '\\b');

function doTree(n) {
if (n.className && z.test(n.className)){
cArray.push(n);
}
for (var i=0, len=n.childNodes.length; i<len; i++) {
doTree(n.childNodes[i]);
}
}
doTree(n);
return cArray;
}

--
Rob
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript>...
11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
4
by: Logico | last post by:
Hi everybody, I need to do a function in javascript to check or uncheck all checkboxes with the same id. I want this function to work in every form and every page of my site, as I will use the same...
4
by: maya | last post by:
I'm trying to learn CSS2, find some aspects of it quite confusing.. here, http://www.w3.org/TR/REC-CSS2/selector.html#q1 I see this: E F : Matches any F element that is a descendant of an E...
3
by: peter | last post by:
I have a weird problem in some code I am writing. The user selects a number of files from a list and then can select an option which will rename the selected files. Before the process starts, a...
9
by: Harlan Messinger | last post by:
Has anyone produced a tool that identifies and lists all the selectors found among a page's stylesheets that match a particular element, along with the properties applied in connection with each of...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
2
by: =?iso-8859-1?q?Jean-S=E9bastien?= | last post by:
Hello, I'm using yahoo css template and designing application with ROR. I'd like to access the elements with no explicit id (starred lines), and i must not add some explicit id. ...
3
by: uremog | last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.