1

What I'm try to accomplish is create a jqyery plug in that will control the CSS on targeted paragraph.

I have done some research on the custom plug-in's and have not found any article explaining what i need. I tried creating the bottom code snipped but it didn't work, am i missing something or incorrect all together.

When creating a plugin does it follow the conventional jquery setting ? Books or url is also appreciated

(function($){
$.fn.changeletter= function(options){



var setting = $.extend({
color:"white",
backgroundColor:"red",
font-size:"15px"},options);


return this.css({
color:setting.color,
backgroundColor:setting.backgroundColor,
font-size:setting.front,
    });


};

}(jQuery));


//Code

 $("p").changeletter({
color:"red",
backgroundColor:"black",
font-size:"100px",
});
2
  • i would suggest you go through Addy Osmani article on jQuery plugin structure its quite easy and simple to start on: smashingmagazine.com/2011/10/11/… Commented Apr 13, 2014 at 8:15
  • 1
    You need to camelCase, or quote, font-size (fontSize or 'font-size'). Have you checked your browser's JavaScript console? Because that should have raised an error. Commented Apr 13, 2014 at 8:18

1 Answer 1

1

Hey I have modified your plugin like this.This is working

(function($) {
        $.fn.changeletter = function(options) {
            debugger;
            var setting = $.extend({
                color: "white",
                backgroundColor: "red",
                fontSize: "15px"
            }, options);
            return this.css({
                'color': setting.color,
                'background-color': setting.backgroundColor,
                'font-size': setting.front,
            });
        };
}(jQuery));

I guess you got now where you missing.

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

5 Comments

ahh i got one mistake . instead of setting.fontSize i wrote setting.front. So if u replace variable with right name then it will be working
It worked !!!! follow up question..... would you happen to have a great resources website to improve my plugins?
i didnt get your question? please elaborate your question.
Is there a web(besides Jquery.com) where i can acquire additional information on how to create plug - ins for jquery.
This is my recommendation for quick start gist.github.com/addyosmani/1184226 .

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.