Я не могу выбрать элемент и изменить содержимое внутри него, вот мой html
<div class="like_user_wrapper" id="<?php echo $post_id.'like_user_wrapper' ;?> ">
hello, world
</div>
<span class="post_bottom_bar">
<img class="thumb_icon" onmouseover="
var post_id=<?php echo $post_id ?>;
$.ajax({
url:'ajax_like_user.php',
method:'post',
data:{post_id:post_id},
success:function(data){
$('<?php echo '#'.$post_id.'like_user_wrapper' ?>' ).html('hello');
}
})
" >
Я не могу поменять его на привет, когда моя моя мышь над значком
У вас есть дополнительное пространство в части id = "". Измените его на:
id="<?php echo $post_id.'like_user_wrapper' ;?>">
Обратите внимание на пробел после удаления ;?>
.
Я думаю, что вам нужно сделать что-то вроде этого:
HTML:
<div class="like_user_wrapper" id="<?php echo $post_id.'like_user_wrapper';?>">
hello, world
</div>
<span class="post_bottom_bar">
<img class="thumb_icon" id="<?php echo $post_id;?>" >
</span>
Javascript:
$(document).ready(function(){
$('.thumb_icon').mouseover(function(){
var post_id = $(this).attr("id");
$.ajax({
url:'ajax_like_user.php',
method:'post',
data:{post_id:post_id},
success:function(data){
$('#' + post_id + 'like_user_wrapper').html('hello');
}
});
});
});
вы можете сделать это:
<img class="thumb_icon" />
<script>
$(".thumb_icon").mouseover(function(){
var post_id=<?php echo $post_id ?>;
$.ajax({
url:'ajax_like_user.php',
method:'post',
data:{post_id:post_id},
success:function(data){
$('<?php echo '#'.$post_id.'like_user_wrapper' ?>' ).html('hello');
}
})
})
</script>
или
<img class="thumb_icon" onmouseover="mouseoverImg();" />
<script>
function mouseoverImg(){
var post_id=<?php echo $post_id ?>;
$.ajax({
url:'ajax_like_user.php',
method:'post',
data:{post_id:post_id},
success:function(data){
$('<?php echo '#'.$post_id.'like_user_wrapper' ?>' ).html('hello');
}
})
}
</script>
$('.thumb_icon').mouseover(function(){})