Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Got this problem too long for now.
Divs created by a loop:
PHP
<?php
	$id = get_the_ID();
	echo '<div id="post-'.$id.'" class="box" >';
?>



On Clicking on a .box div, another div id:zoom append to the div clicked:
JavaScript
var clickedElement;
$('.box').click(function() {
	clickedElement = $(this).attr("id");
});


$('#' + clickedElement).append('<div id="zoom"></div>');



This doesnt work, nothing gets appended.
The following code works:

JavaScript
$('#post-23').append('<div id="zoom"></div>');


So, I really dont know what the problem is... perhaps a selector... dunno

Thanks for help!!!

Regards, Simon
Posted

Try like this,
JavaScript
var clickedElement;
$('.box').click(function() {
	clickedElement = $(this).attr("id");
	$('#' + clickedElement).append('<div id="zoom">hello this is newly appended div.</div>');
});
 
Share this answer
 
v2
Comments
SimonBa 11-Jan-13 5:30am    
Thanks, sadly it doesnt work, even with a fix ID
Sanjeev Alamuri 11-Jan-13 5:31am    
Try to put some text in div then check, empty div show you nothing. check my updated solution.
you should be using:

C#
$('.box').click(function() {
    $(this).append('<div id="zoom"></div>');
});


Regards
Pawan
 
Share this answer
 
Comments
SimonBa 11-Jan-13 5:30am    
Thanks, sadly it doesnt work, even with a fix ID
Rai Pawan 11-Jan-13 5:57am    
you can cross check the following:
1. your jquery code is withing $(document).ready()
2. if your js code is place in a separate .js file, check that you have referenced the corresponding .js file.
- pawan
Rai Pawan 11-Jan-13 7:05am    
Also check whether the original div that you've been creating in a loop have some content or not? if they don't have any content, how are you supposed to click on it?
- pawan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900