Forum Moderators: open

Message Too Old, No Replies

using cssQuery

can't get started

         

ctoz

6:07 am on Nov 28, 2009 (gmt 0)

10+ Year Member



I'm not getting any reaction to a code which uses Dean Edwards' cssQuery.

The code doesn't run, and it's not throwing any error messages in Firefox or Opera.

That sound like possibly the cssQuery scripts aren't being accessed, but the paths to the scripts look ok to me.

Any help appreciated.. perpetual newbie.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>TEST PAGE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="Play.css">
<script type="text/javascript" src="cssQuery.js"></script>
<script type="text/javascript" src="cssQuery-standard.js"></script>
<script type="text/javascript" src="cssQuery-level2.js"></script>
<script type="text/javascript" src="cssQuery-level3.js"></script>

<script type="text/javascript">
var line1 = cssQuery("div:nth-child(6)")

function test1() {
for (i=0; i<line1.length; i++) {
if (line1.item[i].textNode == "---" && line1.parentNode.item[i].className == "hex") {
line1.parentNode.style.color = "red"; }
}
}
</script>
</head>
<body onload="test1()">

<div id="HEX">
<!-- HEXES row 8 -->
<div class="hex" id="H01">
<p>___</p>
<p>___</p>
<p>___</p>
<p>___</p>
<p>___</p>
<p>___</p>
<p class="num0">1</p></div> (and another 63 divs...)

daveVk

11:04 am on Nov 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



var line1 = cssQuery("div:nth-child(6)")

this needs to happen after onload, try moving it.

<script type="text/javascript">
function test1() {
var line1 = cssQuery("div:nth-child(6)");
for (i=0; i<line1.length; i++) {
if (line1.item[i].textNode == "---" && line1.parentNode.item[i].className == "hex") {
line1.parentNode.style.color = "red"; }
}
}
</script>

Not familiar with cssQuery, looks a lot like jsQuery ?

ctoz

7:48 pm on Nov 28, 2009 (gmt 0)

10+ Year Member



Thanks, getting somewhere: used your suggestion, also dropped unnecessary "if" statement:

function test1() {
var line1 = cssQuery("div:nth-child(6)");
for (i=0; i<line1.length; i++) {
if (line1.item[i].textNode == "---") {
line1.parentNode.style.color = "red"; }
}}

It now throws this message: "Error: line1.item is undefined".

This is first attempt at using a js library, from: [dean.edwards.name...] .

" cssQuery() is a powerful cross-browser JavaScript function that enables querying of a DOM document using CSS selectors...

Syntax
elements = cssQuery(selector [, from]);
where selector (required) is a valid CSS selector and from (optional) is a document, element or array of elements which is filtered by selector.

The function returns a JavaScript array of elements. If there is no match, an empty array is returned. "

If the error message is about an item in the array, it sounds like the array is not actually formed?

daveVk

11:26 pm on Nov 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



line1[i] instead of line1.item[i] maybe ?

Look at jsQuery, much the same principle but taken further ?