0

in order to center all of the excel app web parts on a sharepoint 2013 sp1 page, I thought I could use jquery to do so. I tried the following code to handle horizontal centering. unfortunately the function seems never to be called.

I would expect 9 alert() since there are 9 divs on the page matching the selector. in other words there are 9 divs with the class="ewr-sheetcontainer ewr-grdblkcontainer ewa-scrollbars". yes it has 3 classes and css allows this type of selection but maybe jquery does not.

this code is embedded on the page and jquery is enabled for the site collection.

does anyone see a problem with the script, function, or the way each is called? the goal is adjust the left attribute for the selected div.

<script type="text/javascript">

$(document).ready(function() { 
    $("div.ewr-sheetcontainer ewr-grdblkcontainer ewa-scrollbars").each( function () {
        this.css("position","absolute");
        this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + 
                                                    $(window).scrollLeft()) + "px");
        alert("hello");
        return this;
    } );

}); 

</script>

1 Answer 1

1

Try this, you seem to missed the dots for specifying the classes.

$(document).ready(function() { 
    $("div.ewr-sheetcontainer .ewr-grdblkcontainer .ewa-scrollbars").each( function () {
        this.css("position","absolute");
        this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
        alert("hello");
        return this;
    });

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

1 Comment

well it looks like jquery only allows one class selector. that, or I don't know how to select divs with multiple classes. I tried your method which failed. then I cut back to one class as in $("div.ewr-sheetcontainer").each(....) and the iteration worked. if jquery has this limitation, then css or inline html offers more flexible selection. I was trying to limit the divs selected by using the more demanding criteria. thanks for the help. I will still research the jquery selector - I am not a jquery guy.

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.