0

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

2
  • Textarea value is string in your case you must to add Javascript object or want to add only 1 property ? Commented Jul 7, 2013 at 8:38
  • can you post a sample input ? Commented Jul 7, 2013 at 8:38

2 Answers 2

4

You could try something like:

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

jsFiddle

Sign up to request clarification or add additional context in comments.

3 Comments

Oh yes indeed, you can remove this. It's used for logging messages to the console.
@Manoz console.log is used for troubleshooting code - it outputs different values you specify to the console to see what's going on and when. It's not necessary in production!
@Stefan v., That was quick one. +1.
1

Maybe try this

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

pass in background,redin text area

1 Comment

Awesome and easy one. Taught me something new today +1.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.