[development] How can I refer to the shopping cart using document.getElementById if it does not have an id?

Carl Wiedemann carl.wiedemann at gmail.com
Fri Jan 28 17:15:54 UTC 2011


jQuery ships with Drupal. Use class-based selectors
http://api.jquery.com/category/selectors/

alert($(".pane-uc-cart-0").html());

However, if you are adding JS 'inline' it is added to the <head> which
executes before the rest of the DOM is loaded and so you won't get any
response. Use $(document).ready(function(){ ... }); or Drupal.behaviors.foo
= function() { ... } instead, or simply add it to the footer.

On Fri, Jan 28, 2011 at 9:34 AM, John Mitchell <mitchelljj98 at gmail.com>wrote:

> I am trying to get the id for the drupal shopping cart widget so that I can
> refer to it within javascript.  When I look at the shopping cart div within
> firebug (see below) it only lists the class and not the id and I tried
> referring to the class like it was the id but it was not recognized (i.e.
> drupal_add_js('alert(document.getElementById("panel-pane pane-block
> pane-uc-cart-0").value)','inline');
> ).
>
> <div class="panel-pane pane-block pane-uc-cart-0">
>
> How can I refer to the shopping cart using document.getElementById if it
> does not have an id?
>
> --
> John J. Mitchell
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110128/6d163bd7/attachment.html 


More information about the development mailing list