There is this markup:
<div class="product-list-wrapper">
<div class="exposed-wrapper">
<details class="js-form-wrapper">
<div class="form-item">
<label>Crew Neck T-Shirts</label>
</div>
</details>
<details class="js-form-wrapper">
<div class="form-item">
<label>V-Neck T-Shirts</label>
</div>
</details>
</div>
<div class="rows-wrapper">
<div class="tags-buttons-wrapper">
<div class="tags-container"></div>
</div>
</div>
</div>
A task:
When clicking on the
<label>with the value Crew Neck T-Shirts, must be created<div>with thetag-labelclass intags-containersand must be created two<span>intag-labeldiv, where the second one will have theclose-btnclass.On the same click, put the Crew Neck T-Shirts value in the first
<span>of the one without the class.
And when I click on the <label> with the value V-Neck T-Shirts, I need to do the same.
As a result, there should be two tag-label containers in tags-container like this:
<div class="tags-container">
<div class="tag-label">
<span>Crew Neck T-Shirts</span>
<span class="close-btn"></span>
</div>
<div class="tag-label">
<span>V-Neck T-Shirts</span>
<span class="close-btn"></span>
</div>
</div>
To do this, I wrote the following jquery code:
jQuery(document).ready(function () {
$(".product-list-wrapper .js-form-wrapper .form-item label").on('click', function() {
$(".product-list-wrapper .rows-wrapper .tags-container").append('<div class="tag-label"><span></span><span class="close-btn"></span></div>');
$('.product-list-wrapper .rows-wrapper .tags-container span').val('WWW');
});
The problem is that it does not work, and besides, I am passing here just a random text 'WWW' and I need to transfer the value from the labels.
Also, I wrote this code in sandbox:
https://jsfiddle.net/petroyarmolenko/x17sn43q/21/
Visually, what I do should look like this:
