Reputation: 33
<?php
echo '<script>var newUL = $("<ul>for($i=1;i<=4;i++){"<li>test</li>";}</ul>");$("#filemanager li").click(function(){$(this).append(newUL);});</script>';
?>
I want to put < li > in < ul > tags, using "for" function I want to generate lines in an unordered list using for function
Upvotes: 0
Views: 50
Reputation: 877
(UPDATED AGAIN)
<?php
echo '<script>var newUL = $("<ul>';
for($i=1;$i<=4;$i++)
{
echo "<li>test</li>"; // UPDATED according to new code
}
echo '</ul>");';
echo "\n";
echo '$("#filemanager li").click(function(){$(this).append(newUL);});</script>';
?>
Upvotes: 1
Reputation: 36511
There is no reason at all to use PHP for this task, PHP will not run on click (unless you are using AJAX to make a call to the server). You only need Javascript for this:
$("#filemanager li").click(function(){
$(this).append('<ul><li>test</li></ul>');
});
If you need to do this for an arbitrary number of elements:
$("#filemanager li").click(function(){
var elem = '<ul>';
for(var i = 0; i <= 4; i++){
elem += '<li>test</li>';
}
elem += '</ul>';
$(this).append(elem);
});
Upvotes: 0