Sean Kerwin
Sean Kerwin

Reputation: 89

Jquery get value of child div and replace text elsewhere on page

I have a fiddle here to explain what I am using, https://jsfiddle.net/wvz9p3e7/1/

This is usually in PHP and has a loop for 7 or 8 garments, so what I want to do, is in the window on the right in the fiddle, when you click one of the boxes, the window on the right fills with the correct Garment Id and Base price,

I can get the garment ID to work, but how to i get JS to find the base price and fill out the text on the right?

$(document).ready(function() {
            $(".garment-select").click(function(event) {
                $("#garmentID").text(event.target.id);
                $(".garment-select").not(this).removeClass('selectecGarment');
                $(this).toggleClass( "selectecGarment" );
            });

            $(".garmentPanel > .").click(function(event) {
                $("#garmentID").text(event.target.id);
            });

        });

Upvotes: 0

Views: 104

Answers (2)

Martin Peter
Martin Peter

Reputation: 3911

There are several ways to solve this. Straight forward:

$(".garmentPanel").click(function() {
     $("#garmentID").text($(this).attr('id'));
     $("#garmentBasePrice").text($(this).find('.garmentPrice').text());
});

See this fiddle

Upvotes: 1

Rohit Kumar
Rohit Kumar

Reputation: 2031

use this jQuery statement to do retrieve that price -

$('#garmentBasePrice').html($(this).next().next().text());

Fiddle

Upvotes: 0

Related Questions