简体   繁体   English

使用Jquery,如何更改要单击的对象的CSS?

[英]Using Jquery, how do you change the css of the object you are clicking?

I am working on a very dynamic page which will have a lot of what we will call buttons for simplicity sake (actually are divs). 我正在一个非常动态的页面上工作,为了简单起见,该页面将有很多我们称为按钮的按钮(实际上是div)。

These buttons have a span tag inside which has display:none; 这些按钮内部有一个span标签,其中display:none; . This all of these "buttons" have the Span inside with the css class which has them hidden. 所有这些“按钮”的内部都有跨度,而css类则将其隐藏了。 I can not create an #ID for each one, they are going to be dynamic 我无法为每个ID创建一个ID,它们将是动态的

How can I, using Jquery, animate using .show() just the item being clicked. 我怎样才能使用Jquery在仅单击的项目上使用.show()动画.show() I can not input an ID, because it will be created dynamically with php. 我无法输入ID,因为它将使用php动态创建。

$('.button').click(function(){
    $(this).find('span').show();
})

jsfiddle jsfiddle

Try this 尝试这个

$("div").click(function(){
    $(this).children("span").show();
});

DEMO 演示

More information here 更多信息在这里

$(".className or #idName").css("thecssselector", "thevalue");

看这里

use this jQuery: 使用这个jQuery:

$(document).ready(function(){
    $("tag name or id on which you will click").click(function(){
        $("tagname on which you want to apply the css").css("property_name","property_value");
   });
});

Here have some fiddle. 这里有一些小提琴。

$('div').click(function(){
    $(this).find('span').fadeIn("slow");
});

try this 尝试这个

$(".button").click(function(){
  $("div span").hide();
  $(this).find("span").show();     
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM