Usually I put JavaScript like this :
<head>
<title>Title goes here</title>
<script>
some JavaScript here
</script>
</head>
<body>
some codes here
</body>
but now I have a case that JavaScript code must be generated and equal with number of LI tags on HTML file:
$('#manage-1').click(function(e) {
$(this).next(".manage-content-wrap").find(".manage-content").load("test-manage-1.php");
e.preventDefault();
});
$('#manage-2').click(function(e) {
$(this).next(".manage-content-wrap").find(".manage-content").load("test-manage-2.php");
e.preventDefault();
});
I have an idea to create that JavaScript from PHP by modifying #manage-1 with variable like this : #manage-$i and any other dynamic parts.
but, is it possible to put tag inside like this :
<head>
<title>Title goes here</title>
<script>
some JavaScript here
<?php
PHP code inside script tags
?>
</script>
</head>
Ok, I think we can fix this with just a little refinement of your technique.
You really don’t need multiple .click handlers, you need to have a better selector strategy.
Let’s say you surround your LI’s with this:
Now, you really only need one .click handler:
Mind you, you might have to modify how you find your proper .manage-content element, in this fashion, but you should get the idea.
In this way, also, you’re not tying your interaction on the presentation side with your data inextricably, and you DRY up your code a bit. Almost any time you see yourself needing to spit out auto-generated code that is exactly the same except for a couple details, there is an opportunity to simplify the approach.
Hope this helps!