0

I'm new to this sort of thing but i've created a simple plugin which i hope to end up being a simple WSIWYG editor.

Here is my simple settings part of my plugin

$.fn.ap_wysiwyg = function(options){
        // extend the option with the default ones
        var settings = $.extend({
            width : "800px",
            height : "600px",
        },options);

Here is the inline script inside my HTML to call the plugin

$(document).ready(function(){
  $("#ap-wysiwyg").ap_wysiwyg({
    width : "600px",
    height : "400px",
    css : {
      'background-color' : '#000'
    }
  });
});

Quite simply the width and height from the inline html is overwriting the default settings from my main script which is fantastic but i'm attempting to add CSS such as background-color and margin but they dont seem to be applying in my html. As it stands my div inside html has a style of width: 600px; and height: 400px which is perfect but it's skipping my CSS styling that i wish to manually apply.

var containerDiv = $("<div/>",{
           css : {
               width : settings.width ,
               height : settings.height,
               border : "1px solid #ccc"
           }
       });

Here i go about creating a div on the go which applies my width and height but the idea is that the parsed settings into the plugin can be anything and i need this to pick up the parsed CSS and apply it.

For example it see's there is a margin or background so it adds margin : settings.margin and background-color : settings.background-color

How do i go about this? As my method is clearly not working.

4
  • Can we see the part of the plugin that applies the css to the element? Commented Sep 3, 2014 at 12:56
  • Just realised i submitted this too quickly and missed a bit i'll edit it quickly Commented Sep 3, 2014 at 12:58
  • Done, sorry about that :P Commented Sep 3, 2014 at 13:00
  • can you try removing the single quotes around background-color? Commented Sep 3, 2014 at 13:06

1 Answer 1

1

Instead you could try something to the effect of:

var containerDiv = $("<div/>").width(settings.width).height(settings.height).css(settings.css);

That should apply your settings properly to any element. Let me know if that works for you. Hope it helps!

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

1 Comment

Thanks that's perfect hope this helps any newbies with the same sort of issue :)

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.