0

I'm trying to create a clickable link that changes the css using jquery. I've tried many approaches and nothing seems to work. Hopefully someone here can push me into the right direction.

Button html (in a block):

<a href="#" id="change_css">Change CSS</a>

Button code (in change_css.js):

(function($) {
    Drupal.behaviors.my_node_toggle = {
        attach: function(context, settings) {
            $("#change_css", context).click(function(){
                $('a').css({"color":"#ff0"});  
            });
        }
    };
})(jQuery);

The script is being loaded, but nothing happens when I click on the link.

  • I suggest you put some debug code , like console.log("click fired correctly"); in click handler function to sure that click handler work correctlty – Yusef Aug 19 '14 at 4:59
0

Your problem resides in the way you are calling the css function in jQuery. Try this, it works for me:

(function($) {
  Drupal.behaviors.my_node_toggle = {
    attach: function(context, settings) {
      $("#change_css", context).click(function() {
        $('a').css("color","#ff0");
      });
    }
  };
})(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.