Manoz
Manoz

Reputation: 6587

How to add custom CSS on button click?

I have a button that has some predefined CSS. With this button i have created an action button and a textarea.

Whenever i write some CSS in textarea then it should be added to existing button's CSS when submitting this CSS by action button.

I tried this-

jQuery-

$(function(){
    $('.add').click(function(){
      var custom=$('.textarea').val();
        $('.button').css(custom);

    });
});

But it doesn't seem to be working, How can i do this?

Is iframe Needed here?

Fiddle

Upvotes: 0

Views: 194

Answers (2)

varun
varun

Reputation: 4650

Maybe try this

   $(function(){
        $('.add').click(function(){
          var custom=$('.textarea').val().split(',');        
             $('.button').css(custom[0],custom[1]);
        });
    });

pass in background,redin text area

Upvotes: 1

Stefan
Stefan

Reputation: 1106

You could try something like:

$('.button').attr("style", custom);

jsFiddle

Upvotes: 4

Related Questions