Note that there are some explanatory texts on larger screens.

plurals
  1. POonclick help - reading the value of a specific class, part 2
    primarykey
    data
    text
    <p>I am working on integrating a javascript shopping cart, simplecart-js, into a Jquery LightBox, Yoxview. Yoxview has an option to add button links in the popup title pane for various options, downloading, shopping cart, etc. The relevant code for my shopping cart button is:</p> <pre><code>var yoxviewCartButton = $("&lt;a&gt;", { title: "Add to cart", }); $('.simpleCart_shelfItem').each(function () { var name = $(this).children('span')[0].firstChild.data; var price = $(this).find('span&gt;span').text().replace('$', ''); var thumbs = $(this).find('span&gt;span&gt;span').text().replace('$', ''); var button = $('&lt;button/&gt;', { type: 'button', 'class': 'shopping_button' }); button.append($('&lt;img/&gt;', { src: 'yoxview/images/yoxview_cart_icon.png', title: 'Add to cart', width: 18, height: 18 })); button.click(function () { simpleCart.add('name=' + name, 'price=' + price, 'quantity=1', 'thumb=' + thumbs); }); yoxviewCartButton.append(button); }); $(".yoxview").yoxview({ infoButtons: { download: yoxviewDownloadButton, cart: yoxviewCartButton }, onSelect: function (i, image) { $.yoxview.infoButtons.download.attr("href", image.media.src); $.yoxview.infoButtons.cart.data("yoxview_cart", image.media.src); $.yoxview.infoButtons.cart.click(function () { $("#cart").show(); $.yoxview.close(); }); } }); </code></pre> <p>The html is:</p> <pre><code>&lt;a class="item yoxview simpleCart_shelfItem" href="pics/pic0.png" title="Title 1"&gt; &lt;img class="content" src="pics/pic0.png" title="Title 1"/&gt; &lt;span class="caption item_name"&gt; Title 1 &lt;span class="item_price"&gt;$14.99&lt;/span&gt; &lt;span class="item_thumb"&gt;pic5.png&lt;/span&gt; &lt;/span&gt; &lt;/a&gt; </code></pre> <p>I realize I need to clean up the html and get rid of all the nested spans and clean up the code to use <code>text()</code> , as bobince suggested in my last question. My next task!</p> <p>I have it working well, I can <code>show()</code> the invisible cart div and close the lightbox window when I click on the Cart button and the shopping cart works.</p> <p>The 2 problems I can't get are</p> <ol> <li><p>I can't get the thumbs to be read with my code, but all other data works well</p></li> <li><p>and more importantly, The same number of shopping cart buttons as "<strong>simpleCart_shelfItem</strong>" images show up in the lightbox. One is great but 6 looks a bit overdone (or desperate for a sale? lol) . If anyone has some direction for me to go in to have the code show only the one button for the corresponding "<strong>simpleCart_shelfItem</strong>", not all, I would greatly appreciate it!</p></li> </ol> <p>I updated my code and I am getting the code closer to working. I have fixed the multiple cart buttons and when clicked, the cart data inputs as it is supposed to into the cart, except that all items with the class "<strong>simpleCart_shelfItem</strong>" load into the cart instead of just the one I click the cart button for. Here is my updated code:</p> <pre><code>var yoxviewCartButton = $("&lt;a&gt;", { title: "Add to cart" }); yoxviewCartButton.append($("&lt;img&gt;", { src: "yoxview/images/yoxview_cart_icon.png", alt: "Add to cart", css: { width: 18, height: 18 } })); $(".yoxview").yoxview({ infoButtons: { download: yoxviewDownloadButton, cart: yoxviewCartButton }, onSelect: function(i, image) { $.yoxview.infoButtons.download.attr("href", image.media.src); $.yoxview.infoButtons.cart.data("yoxview_cart", image.media.src); $.yoxview.infoButtons.cart.click(function () { $('.simpleCart_shelfItem').each(function () { var name = $(this).children('span')[0].firstChild.data; var price = $(this).find('span&gt;span').text().replace('$', ''); var thumbs = $(this).find('span&gt;span&gt;span').text().replace('$', ''); simpleCart.add('name=' + name, 'price=' + price, 'quantity=1', 'thumb=' + thumbs); }); $("#cart").show(); $.yoxview.close(); }); } }); </code></pre> <p>here is a link to the test page:</p> <p><a href="http://macosxsupport.com/yoxview_cart/" rel="nofollow">http://macosxsupport.com/yoxview_cart/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload