简体   繁体   中英

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).

These buttons have a span tag inside which has display:none; . This all of these "buttons" have the Span inside with the css class which has them hidden. I can not create an #ID for each one, they are going to be dynamic

How can I, using Jquery, animate using .show() just the item being clicked. I can not input an ID, because it will be created dynamically with php.

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

jsfiddle

Try this

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

DEMO

More information here

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

看这里

use this 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();     
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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