Can you pull a value from div based on ID

Discussion in 'JavaScript' started by GrassR00ts, Oct 10, 2008.

  1. #1
    Hello All

    Iam on a hosted ecommerce solution. They do not provide me the variables use in show product price and such. Each of the products are displayed on the page inside of <div> tags and each has an id=

    Could I use a javascript to pull these values based on the id of the div box?

    Thanks for the help!:)
     
    GrassR00ts, Oct 10, 2008 IP
  2. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Sure, simple example on how
    <html>
    <head>
    <script type="text/javascript">
    function getContentFromDiv(divID) {
        var divContent = document.getElementById(divID).innerHTML;
        alert(divContent);
    }
    </script>
    </head>
    <body>
    <div id="i_am_a_div">Product: Nokia Bazooka XL-3264785.<br /> Price $0.002 ..  etc... </div>
    <script type="text/javascript">
    getContentFromDiv('i_am_a_div');
    </script>
    </body>
    </html>
    Code (markup):
    :)
     
    wing, Oct 10, 2008 IP
  3. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    and the main idea:
    var divContent = document.getElementById('the_div_id').innerHTML;
    Code (markup):
     
    djzmo, Oct 10, 2008 IP