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.

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

1 Answer 1

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);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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