I have some problem with changing <span>
content </span>
.
I get response from AJAX but i can't change <span>
element.
Here is my html:
<?php $i = 1; ?>
@foreach($Hotels as $hotel)
<img src="{{ asset($hotel->img) }}" width="800" height="533" class="img-responsive" alt="{{ $hotel->HotelName }}">
<div id="score"><span>{{ $hotel->score }}</span>{{ $hotel->rating }}</div>
From/For Night
<span class="price">
<sup>$</sup>
<span id="H{{ $i }}" data-hotel-id="{{ $hotel->HotelID }}">...</span>
</span>
<div class="hotel_title">
<h3>{!! preg_replace("/ /", " </strong>", '<strong>'.$hotel->HotelName, 1 ) !!}</h3>
<div class="rating">{{ $hotel->HotelClass }}</div>
</div>
<?php $i++; ?>
@endforeach
And my JS:
$(document).ready(function(){
for(var i=1; i<=6; i++){
var data = $('#H'+i).data('hotelId');
$.get('/online/prices/'+data, function(prices){
//Try to change my span
$('#H'+i).text(prices);
});
}
});
But if i change $('#H'+i).text(prices);
to $('#H1').text(prices);
it will work only for <span id='#H1'>
.
UPDATE