使用jQuery动态更改HTML元素的宽度

Dynamically changing the width of an HTML element using jQuery

本文关键字:元素 HTML jQuery 动态 使用      更新时间:2023-09-26

我正在尝试使用jQuery 更改悬停时li元素的宽度

echo"<div id='film_container'><ul>";
while($row= mysql_fetch_array($result))
{
extract($row);
echo"<a href='#'><li class='film_list'> <img class='poster' src='$poster_small'/>      
<span>$film_name</span></li></a>";
}
echo"</ul></div>";

这是jquery

 <script>
 $(document).ready(function(){
 $('li .film_list').hover(function(){
 $(this).css("width","180px");
 });
 });
 </script>

这里jquery-css方法不起作用,有人能提出什么建议吗?

<script>
 $(document).ready(function(){
 $('li.film_list').hover(function(){
 $(this).css("width","180px");
 });
 });
</script>

删除选择器中的空间

删除li和.film_list之间的空格。您的选择器意味着您的li标记中有一个元素,该元素包含类'film_list',而不是li本身。