I have some images created with php and i want to put each of them inside a li. Here is my working code :
for ( i = 0; i < MaxNum; i++) {
$('li#' + i + '').html('<img src="http://www.address.com/somephp.php?Num=1" />')
}
All i want to do now is put the i variable in the the image source in order to have something like this:
for ( i = 0; i < MaxNum; i++) {
$('li#' + i + '').html('<img src="http://www.address.com/somephp.php?Num="+i />')
This code is not working. Is it possible to that with this way?
for ( i = 0; i < MaxNum; i++) {
$('li#' + i).html('<img src="http://www.address.com/somephp.php?Num='+ i +'" />')
}
Problem to you code
'<img src="http://www.address.com/somephp.php?Num="+i />' in this code i is treated as String, not a variable.
to remove + '' part from $('li#' + i + '').
The i is still inside your string, you need something like this:
for ( i = 0; i < MaxNum; i++) {
$('li#' + i + '').html('<img src="http://www.address.com/somephp.php?Num='+i+'" />');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With