1

I'm trying to set some labels right 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 $(this) is returning what I believe to be the window width.

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

0

2 Answers 2

4

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%');
Sign up to request clarification or add additional context in comments.

1 Comment

nice, didn't know you could use a function like that
1

Do it in an each loop then you can use this:

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

Comments

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.