Simple first-child js?
Posted
by Glister
on Stack Overflow
See other posts from Stack Overflow
or by Glister
Published on 2010-04-24T16:25:07Z
Indexed on
2010/04/24
16:43 UTC
Read the original article
Hit count: 483
JavaScript
|first-child
Searching for a simple first-child detection via javascript
(no framework).
It should add some class for the first child of the element. Like a css-hacks for ie, but in javascript and for a html file.
Must work similar to :first-child
When I say no framework, I mean some code like this:
<script type="text/javascript">document.documentElement.id = "js"</script>
For example:
<div class="terms">
<dl>
<dt>Term 1 name</dt>
<dd>Term 1 description</dd>
</dl>
<dl>
<dt>Term 2 name</dt>
<dd>Term 2 description</dd>
</dl>
<dl>
<dt>Term 3 name</dt>
<dd>Term 3 description</dd>
</dl>
</div>
Three <dl>
, the first one includes Term 1.
This css won't work in IE6, thats why I'm searching for a javascript solution. CSS-hacks are not allowed.
.terms dl:first-child { float: right; }
© Stack Overflow or respective owner