У меня 3 вкладки. На первой вкладке есть ссылка, которая открывает вторую вкладку. На второй вкладке есть серия изображений. Я пытаюсь достичь, когда пользователь нажимает на любое из изображений на второй вкладке, это изображение копируется обратно в div, где пользователь впервые щелкнул, чтобы открыть эту вкладку. Все, что я пробовал до сих пор, провалилось. Мне нужно знать идентификатор кликаемого изображения и скопировать это изображение. Если пользователь затем щелкнет другое изображение, оно скопирует и это.
<div id="demoTabs">
<ul>
<li><a href="#bike">Bike</a></li>
<li><a href="#coach">Coach</a></li>
<li><a href="#truck">Truck</a></li>
</ul>
<div id="coach">
<div id="firstDiv">
<img src="assets/img/english/calltoadventure.png" id="imgone" class="theImage" value="Copy"/>
<br>
<img src="assets/img/english/cinemastudies.png" id="imgtwo" class="theImage" value="Copy"/>
</div>
<div id="myDiv">
<img src="assets/img/english/calltoadventure.png" id="img19" class="theImage" value="Copy"/>
<br>
<img src="assets/img/english/cinemastudies.png" id="img20" class="theImage" value="Copy"/>
</div>
</div>
<div id="bike">
<div id="secondDiv">
<a href="#coach" class="open-tab" data-tab-index="1">
<img src="assets/img/bike.png" id="english"/></a></div>
</div>
<div id="truck"><img src="assets/img/truck.jpg"/></div>
</div>
</body>
<script>
$(document).ready(function() {
var $selectedOption =""; //the option user clicks on which determins which tab to open
var $theDiv = ""; // the div where the image to copy resides
var $thecallingDiv = ""; // the div where the image is to be placed
var $selectedImage = ""; // the image the user selects
$('#demoTabs').tabs({ active: 0 });
$('.open-tab').click(function (event) {
$selectedOption = $(this).children('img').attr('id');
$thecallingDiv = $(this).closest('div').attr('id');
$('#demoTabs').tabs("option", "active", $(this).data("tab-index"));
});
$("img.theImage").on("click",function() {
// get the id of the image selected
$subjectImage = $(this).attr('id');
// get the id of the closest div
$theDiv = $(this).closest('div').attr('id');
$($selectedImage).clone().attr('id',$selectedImage).append($thecallingDiv);
});
</script>