I am really new to JavaScript, and Im basically trying to build a simple Script to get information from a site like Walmart.com. Im using firebug to test my little snippets. Im having a problem getting the price.
This is the my code:
var price = document.getElementById('clearfix camelPrice');
console.log(price);
I also tried ".camelPrice" with out the period and I keep getting null.
Thanks a lot in advance!
In this case, you’re using the wrong method.
getElementByIddoes exactly what it says, it gets an element by its id. Looking on Walmart.com, ‘camelPrice’ is a CSS class.We can still get elements by a class. What you want is
document.getElementsByClassName(). Further, you can pass multiple arguments togetElementsByClassNamelike so:This grabs all elements that have both the
clearfixandcamelPriceclasses set.