0

I am not a JQUERY Expert and want to know if its possible to select "Items with no id defined that are nested and have a certain css class defined" ?

Example:

When I look at the downloaded CSS and match rules here is the div:

<div id="type" class="productType">Test Descript <span>$399.00</span> </div>

The CSS that gets applied to the span is:

.rightInfoDiv h1 div.productType {font-size: 14px;line-height: 18px;font-weight: normal;margin-bottom: 0.1em;}

I want to be able to select the "span" so I can get a price. Is this possible ? Any pointers would be appreciated

Thanks very much

4 Answers 4

3

You can target the parent div and then target the child-span

var price = $('#type').children('span').text();
console.log(price); // will output $399.00
Sign up to request clarification or add additional context in comments.

2 Comments

what if there would be more span tags?
You could use .eq() to target the one you're after. .children('span').eq(0) - will target the first span, .eq(1) the second etc etc.. However it would be better to give the price span a class, and just target it directly.
1

I really don't uderstand that statement: "Items with no id defined that are nested and have a certain css class defined". Items doesn't need to have any id or even class. If you want to do that just:

var spans = $('.productType span');

Comments

0

You can do:

var x = $("#type span").text();

x is now $399.00

Comments

0
var item = $("#type span").text();

Demo ---> http://jsfiddle.net/UXtJD/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.