css-selectors

Best way to find DOM elements with css selectors

What's the easiest way to find Dom elements with a css selector, without using a library? function select( selector ) { return [ /* some magic here please :) */ ] }; select('body')[0] // body; select('.foo' ) // [div,td,div,a] select('a[rel=ajax]') // [a,a,a,a] This question is purely academical. I'm interested in learning how thi...

jQuery: What is returned if $('#id') doesn't match anything?

What is returned if $('#id') doesn't match anything? I figured it would be null or false or something similar so I tried checking like so: var item = $('#item'); if (!item){ ... } But that didn't work. ...

Applying Style to last li in a ul with CSS / Jquery

Given the following HTML: <ul> <li><div>Some content</div></li> <li><div>some more content</div></li> <li><div>final content</div></li> </ul> I would like to apply a top border around each div. On the last div I would like to put a bottom border. I am targeting IE7/8. I have the top border working fine, I need help getting th...

greasemonkey script that outputs all data corresponding to xpath

I would like to write a greasemonkey script that given an xpath returns all of the output of that xpath executed on the current page in a .txt file with one result per row. How do I do this? EDIT: Its ok if the output is not written to a file. I just want to have it displayed. ...

Style table cells using jQuery

I'm trying to style table cells within a table based upon whether or not the contain the character | in the url or not (don't ask, dealing with SharePoint). Sample HTML; <table> <tr> <td class="ms-cal-workitem"> <table> <tr> <td class="ms-cal-monthitem"> <a href="http://localhost:4657/1"&gt;Event 1</a> </td> </tr> </table> </td> </tr> ...

Can't figure out the jQuery selector

So Basically I am trying to keep the top level categories image of a down arrow turned on while hovering over the submenu's elements. I want to do this through jQuery on a hover function however I cannot for the life of me get a selector to target the sub menu items. Here is the code I am trying to run: $(document).ready(function() { ...

CSS - Syntax to select a class within an id

What is the selector syntax to select a tag within an id via the class name? For example, what do I need to select below in order to make the inner "li" turn red? <html> <head> <style type="text/css"> #navigation li { color: green; } #navigation li .navigationLevel2 { color: red; } </s...

PrototypeJS: Selecting the odd subset of visible children

This is related to my previous question about selecting visible elements. Now, here's the twist: Let's say I want to select the odd children only from the set of visible children of an element. What would be the best way to do this? Edit: here is an example of my input and expected output. <!-- A list with some visible and invisible ch...

jquery access to a user specific collection via table index?!

i have a table <table> <tr> <td class="myA">Data...1a</td> <td class="myA">Data...2a</td> <td class="myA">Data...3a</td> </tr> <tr> <td class="myB">Data...1b</td> <td class="myB">Data...2b</td> <td class="myB">Data...3b</td> </tr> <tr> <td class="myC">Data...1c</td> <td class="myC">Data...2c</td> <td class="my...

CSS Child vs Descendant selectors

i am abit confused between these 2 selectors div p selects all p within a div whether or not its an immediate decedent? so if the p is inside another div it will still be selected? then child selectors div > p whats the difference? does a child mean immediate child? eg. <div><p> vs <div><div><p> both will be selected? ...

Use of * selector in style sheet to reset styles

At the moment I am just resetting the styles I need at the top of my style-sheet, like: html, body, div, fieldset, form, h1, h2, h3, h4, p, ul, li { margin: 0; padding: 0; } However, I have seen a lot of times that people use: * { margin: 0; padding: 0; } That does seem to make things easier, but somewhere else (don...

What is the difference between jQuery's space and > selectors?

What's the difference between the space and > selectors? And possibly related, how can I look for something that's the direct child of something else, and not lower down the descendant line? ...

YUI 3 Selector for multiple class names

Hello, I have a bunch of divs like this: <div class="bear"></div> <div class="dog"></div> How do I get a nodelist that includes all divs with class of bear and dog? I tried: Y.get(".bear .dog").each(function() { }); But it returns null. Anyone have any suggestions? Thanks! ...

Doing quotes in CSS

I have some legacy CSS I wanted to clean up. Person who wrote it is not available for consultation. The following rule does not validate (CSS 2.1): html[lang=en] q: before, : lang(en) q: before { content: "“"; } Would it be safe to assume that the author mean the following (this validates): html[lang=en] q:before, q:lang(en):befo...

Is there a CSS selector that selects a dt and its associated dd elements?

Definitions lists are a great way to mark up information where some key word is associated with one or more values. Since there is the semantic association of a dt with one or more dd elements, is there a way to use CSS to select these associated items. Consider the following html: <dl> <dt>Foo</dt><dd>foo</dd> <dt>Bar</dt><dd>bar...

Form Input Won't Take Percentage Padding

My form inputs display properly if pixel padding is used, but using a percentage padding for left and right breaks it. I can't figure out why. Demo @ http://stonewatercove.com/test.html It works in Safari, broken in Firefox 3.5.3 OSX. The problem is that when I use a percentage padding, the padding all breaks (hence why the input value...

CSS 3 content selector?

Hey, I am looking for a CSS selector for the following table: Peter | male | 34 Susanne | female | 12 Is there any selector to match all TDs containing "male" ? ...

css selector to match an element without attribute x

I'm working on a CSS file and find the need to style text input boxes, however, I'm running into problems. I need a simple declaration that matches all these elements: <input /> <input type='text' /> <input type='password' /> ... but doesn't match these ones: <input type='submit' /> <input type='button' /> <input type='image' /> <inp...

How many tags can have same id in document

I know there can be only one unique ID attribute per document. To be sure, I need real doc link where this is written. ...

Counting number of elements matching a CSS Selector

How can I count the number of elements that match my CSS selector?? I am trying to use SeleniumRC to test my GWT App and am trying to match elements using CSS selectors. I want to count the number of enabled Buttons in the following HTML. A button is enabled if it is under a td with class="x-panel-btn-td " and disabled if it is unde...