0

I have a script that assigns data-offset-top and data-offset-bottom to an affixed (bootstrap affix) div. At least this is what I am trying to do. For some reason it does not work... anymore.

Is there something wrong with the code bellow or the issue is from somewhere else?

javascript:

$(document).ready(function(){
    var off = $(".navbar-static-top").height() + 80; 
    var off2 = $("footer").height() + 30;
    $(".awrap > div:nth-child(1)").attr('data-offset-top', off.toString(); );
    $(".awrap > div:nth-child(1)").attr('data-offset-bottom', off2.toString(); );           
    $(function() {
        var $affixElement = $('div[data-spy="affix"]');
            $affixElement.width($affixElement.parent().width());
    });
});

Thank you!

3
  • 1
    Could you please provide a jsfiddle.net of your issue, and provide the full html of the page? (preferably both) Commented Aug 11, 2015 at 14:57
  • 2
    Well for one you can remove the ; after the off.toString() and off2.toString(). Commented Aug 11, 2015 at 14:57
  • 1
    Do you get any errors in the Console? Commented Aug 11, 2015 at 14:57

2 Answers 2

2

If you check the console you will most likely be seeing an error saying missing ) after argument list

This is due to

$(".awrap > div:nth-child(1)").attr('data-offset-top', off.toString(); );
$(".awrap > div:nth-child(1)").attr('data-offset-bottom', off2.toString(); );

Most notably the

off.toString();
off2.toString();

You can't have the ; inside the attr function.

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

Comments

-1

It looks like the problem was my use of WooCommerce jQuery Cookie fix. (when I deactivated it things went back to normal). Thank you for your answers!

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.