Xonox Xonox - 1 year ago 68
jQuery Question

jQuery: How can I set css with own width?

I'm trying to set some labels

property so that I can change it on mouse over.

The reason I'm doing this via jQuery is because each one has a different size which doesn't allow to do it via CSS.

This is what I have:

$('#vertical-navigation .label').css('right', $(this).width());

Which, of course, doesn't work, because
is returning what I believe to be the window width.

How can I set the
position with the element own width, for each one?

Answer Source

You can use function parameter like this:

$('#vertical-navigation .label').css('right', function(){
    return $(this).width() + 'px';

Now depending your HTML markup, this could just be enough:

$('#vertical-navigation .label').css('right', '100%');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download