this question has answer here:
i want make function change css property of object. tried code below
function setbgcolor($obj, $color) { $obj.css("background-color", $color); } setbgcolor($(".bg-red"), "red");
and works. to make function called object this
function setbgcolor($color) { $(this).css("background-color", $color); } $(".bg-red").setbgcolor("red");
can help?
you can use jquery prototype this:
$.fn.setbgcolor = function($color) { return $(this).css("background-color", $color); } $(".bg-red").setbgcolor("red");
Comments
Post a Comment