So, I have the following html:
<div class="all_names">
<span class="name" data-name="1">Steve</span>
<span class="name" data-name="2">Mike</span>
<span class="name" data-name="3">Sean</span>
<span class="name" data-name="4">Emily</span>
</div>
<div class="show_names"></div>
Then for js:
jQuery(document).on( 'click', '.all_names', function(e) {
var name = jQuery(this).html(); ????
var name_number = jQuery(this).data("name");????
var show_names ='<div class="show" id="'+ name_number + '">'+ name + '<div>'; ????
jQuery('.show_names').html(show_names);
}
Then the desired end result should be as following:
<div class="show_names">
<div class="show" id="1">Steve<div>
<div class="show" id="2">Mike<div>
<div class="show" id="3">Sean<div>
<div class="show" id="4">Emily<div>
</div>
Here is my question:
When the class all_names
is clicked, I want to save all the names (and corresponding name number
) into variables.
Then, I want to use these values to load the html portion for individual values as shown in the desired end result.
How do I achieve this? Any help will be much appreciated.
Thanks!