General Question

jrpowell's avatar

A JavaScript question. [more inside]

Asked by jrpowell (40562points) March 5th, 2008

I’m hoping to copy and paste together a greasemonkey script. I know nothing of JavaScript..

So what I need..

JavaScript that can find all elements with a CSS class. class=“whatever”

I would like to add a CSS style to any <tr> elements that have that class. The end goal is having the row in the table highlighted with a background color when I hover over it.

And I suck at JavaScript..

Observing members: 0 Composing members: 0

7 Answers

Mangus's avatar

I can’t answer the question directly. But here’s a CSS-only solution that allows for that functionality, I think: http://cssglobe.com/lab/tablecloth/

Scroll to the bottom of the article to change the settings so , for instance, only table rows highlight when moused over.

jrpowell's avatar

Thanks.. But it needs to be JavaScript because I want to modify a existing web page.

jrpowell's avatar

And I should add that this looks like what I need to do.

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_22005907.html

I just don’t want to give my CC info for one answer.

andrew's avatar

All the big JS libraries (jQuery, YUI, scripty) have CSS selection built in. You might want to try jQuery—it’s very lightweight.

You can also just strip out the CSS selection from EXT, we did that for a little bit.. but that’s a bit more involved.

segdeha's avatar

Untested (and, convert curly apostrophes to straight tick marks):

var trs = document.getElementsByTagName(‘TR’);
for (var i = 0, len = trs.length – 1; i < len; ++i) {
if (trs[i].className.match(/myClassName/)) {
trs[i].onmouseover = function () {
this.className = this.className + ’ ’ + ‘hoverClass’;
}
trs[i].onmouseout = function () {
this.className = this.className.replace(/hoverClass/, ’’);
}
}
}

Something like that. It would be easier with a JavaScript library as the starting point.

jrpowell's avatar

Thanks for the info… I think it might be time to learn Javascript. I am still pissed about what Javascript did to the Internet in 1998. I have been hesitant to learn it.

I’m not sure about folding a JS library into a Greasemonkey script.

I’m off to Amazon to buy a “Dummies” book.

segdeha's avatar

What did JavaScript do to the internet in 1998? :-)

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther