Ali
Ali

Reputation: 835

How to call a function on body load

Hi I am using this script to add social media icon into my site.

<div id="menu" class="shareSelector" style="width:250px; height:250px;"></div>

$(document).ready(function () {

    $('.shareSelector').socialShare({
        social: 'facebook,google,pinterest,twitter',
        whenSelect: true,
        selectContainer: '.shareSelector'
    });

});

div gets the content upon clicking on it.Can we call this function without clicking div means on bodyload?

Regards:Ali

Upvotes: 0

Views: 346

Answers (2)

Mark Redman
Mark Redman

Reputation: 24535

The $(document).ready(function () {}); function should run when the page loads.

Have you got the jquery in a <script> tag?

If so, the bindings are setup by the socialShare plugin, so you may need to look at that.

What does whenSelect option do?

Upvotes: 3

deach
deach

Reputation: 360

$(document).ready(function () {

$('.shareSelector').socialShare({
    social: 'facebook,google,pinterest,twitter',
    whenSelect: true,
    selectContainer: '.shareSelector'
});
$('.shareSelector').click()  
});

Dont know about the socialShare plugin but you have an option there which says "whenSelect: true"

try false

Upvotes: 1

Related Questions