I am looking for a way to send to "script.js" file a unique id each item from array, so that i can process data each item individuall
<script href="script.js"></sciprt>
script.js:
$(function(){
$('#box').append( "<p>Box 1</p>" );
}
foreach($items as $item){
echo '<div id="box"></div>';
}
now i got this out put:
<div id="box">box 1</div>
<div id="box">box 1</div>
i need this output (from script file):
<div id="box">box 1</div>
<div id="box">box 2</div>
From your question and from what I've concluded is that, you are trying to get server side information (PHP) to client side (JS).
$i = 0;
foreach($items as $item)
{
echo '<div class="box" id="box_'.$i.'"></div>';
$i = $i + 1
}
Then client side with JS:
function example()
{
$('.box').each(function(){
var id_num = $(this).attr('id').split('_')[1];
//Do something with id_num here
});
}
Try this
foreach($items as $i=>$item){
echo '<div id="box'.$i.'"></div>';
}
where $i
is your own id for array elements.
UPD
In script.js:
$(function(){
var i=0;
while($('#box'+i))
{
$('#box'+i).append( "<p>Box "+(i+1)+"</p>" );
i++;
}
}