Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery add to current width

Tags:

jquery

width

I need this code to, if #vid is present, add 855px to its current width. If not, it should do nothing. I'm not sure how to get jQuery to add to an already existing number, but I'm sure it's pretty simple. Here is the code I have so far:

if ($("#vid").length) {
            $("#img-container").width(+=855),
        } else {
            return false;
        }
});
like image 344
steve Avatar asked Nov 27 '22 23:11

steve


2 Answers

jQuerys methods do not support a += syntax (only exception: css strings), you would need to write:

$("#img-container").width($("#img-container").width() + 855)

or

$("#img-container").css("width", "+=855");
like image 158
jAndy Avatar answered Dec 18 '22 18:12

jAndy


You could try this:

if ($("#vid").length)
{
    $("#img-container").width($("#img-container").width() + 855);
}
like image 41
chigley Avatar answered Dec 18 '22 19:12

chigley