Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-22-2013, 09:10 PM   PM User | #1
Carnelian
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Carnelian is an unknown quantity at this point
Retrieve a div inside a div

I've written a Greasemonkey script to replace the Firefox title bar at woot.com with the item, price, and % left - http://userscripts.org/scripts/show/137091 The problem is that it only works on the main woot-off page - if home.woot is also having a woot-off, you still get the item name from the main page.

Here is the source at home.woot:
Code:
   <div class="offer woot-off ">
  <a class="info" href="http://home.woot.com/offers/smiths-electric-knife-sharpener-7#ref=home.woot.com/header/tab@3.9-home/daily">
  <div class="label">It's a Woot Off</div>
  <div class="title">Smith's Electric Knife Sharpener</div>
  <div class="price">
  <span class="price">$39.99</span>
  <span class="list-price">$99.99</span>
  <span class="percentage">60% off <span class="list-price-label">List Price</span></span>
  </div>
I have tried several different ways to retrieve the title. Right now, I have:
Code:
var subpageItem = document.getElementsByClassName("offer woot-off ").getElementsByClassName("title")[0].innerHTML;
What is the proper syntax? This seems like it should be so simple, but I'm just not getting it.
Carnelian is offline   Reply With Quote
Old 01-22-2013, 09:54 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The problem you have is that the top div in your HTML contains two classes "offer" and "woot-off" but you are searching for "offer woot-off ") which is an invalid class name because class names cannot contain spaces. Because it is invalid that nodelist will be empty.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:49 AM.


Advertisement
Log in to turn off these ads.