Cambiar el estilo de todos los elementos con un evento de clic

I'm in the process of learning JQuery as I'm doing a major redesign of a site. I realize how nice it would be to do some styling in the javascript instead of remembering to add the right css class to every div (apparently, I like to forget such things).

Anyway, I want to add the style cursor: pointer; to all elements that have a click event registered. I think it needs to look something like this:

$("div").Find(/*Has Click Event*/)
  .css("cursor", "pointer");

preguntado el 09 de marzo de 12 a las 16:03

In terms of performance, I think it would be better for you to remember to add this into the styles, than do a javascript workaround -

Lea esto: stackoverflow.com/questions/1236067/… As Curt said, it won't be efficient to use JS to do it but it is possible or get this plugin codenothing.com/archives/jquery/event-filter -

You should avoid applying styles via JS as much as possible, and try to keep content(html), styling(CSS) and functionality(JS) separated. -

1 Respuestas

$("div").each(function () {
    if($(this).data("events") !== 'undefined' && $(this).data("events").click) {
        $(this).css({"cursor": "pointer", "border": "1px solid red"});
    }
});​

Demostración.

respondido 09 mar '12, 16:03

the first selector should be div not asterix ? (for the puprose of this question) - nimchimpsky

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.