jQuery .each()

Messages
12
Reaction score
0
Points
0
Hi,

Am trying to change the formatting of a tr (table row) element with jquery.
I have no control over the table as its generated by another javascript.
the table/tr has no css class

each of the alternate tr has a bgcolor attribute specified... I want to remove the value of this attribute so it turns transparent.
i have paced this script under the javascript that generates the table.

Code:
<script language="JavaScript"> $(document).ready( function() { 
$("#postcontent tr").each( function() { 
$(this).attr("bgcolor", ""); 
}); 
});</script>

But this gives an error in firebug
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
First thing first, the language attribute is deprecated, the correct way would be <script type="text/javascript">.
Otherwise your code should be fine. Now I must ask, did you included the jQuery library?
And last thing, exactly what error is FireBug throwing out?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Either give the entire page or a URL to it.

That error message is saying that $ is not a function, which is saying that jQuery is not there.
 
Messages
12
Reaction score
0
Points
0
it is there...
<script type='text/javascript' src='http://www.pratham.me/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>

err i forgot to mention this all is in a wordpress blog.
www.pratham.me/jobs
 
Last edited:
Messages
12
Reaction score
0
Points
0
If the browser says $ isn't a function, then it isn't defined as a function at the time you're trying to call it. As for the cause, note the call to $.noConflict at the end of ttp://www.pratham.me/wp-includes/js/jquery/jquery.js.

Thanks for the hint mission(eek where did strikethrough go!?) misson* ! :) solved the problem.
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Lessons:

1. Pay attention to error messages. They are often cryptic and sometimes useless, but they usually provide clues as to the source of the problem. Include them in any request for help.

2. Include all the code or a URL. Without the ability to see your copy of jquery.js , finding the culprit would have been impossible.
 
Top