Nikola
Nikola

Reputation: 15038

Javascript function call in HTML - want it in jQuery only

I have a markup like this:

<body onLoad="func();" onResize="func();" id="myId">

I was wondering how can I trigger this just through jQuery?

Upvotes: 0

Views: 47

Answers (3)

Andreas Wong
Andreas Wong

Reputation: 60526

$('body').bind('load resize', func);

Upvotes: 1

Will
Will

Reputation: 20235

$( "body" ).on( "load resize", func );
$( "body" ).trigger( "resize" );

Upvotes: 3

clyfish
clyfish

Reputation: 10450

$(function() {
    $(window).on('resize', func);
    func();
});

Upvotes: 2

Related Questions