call a function using resize()

jquery resize not working
window resize jquery stack overflow
jquery change div height on window resize
jquery window resize
window.onresize not working
div resize event
jquery div resize event example
window .bind resize function

I want to add and event listener to call a function whenever my window resize, but somehow it doesnt work! I tried these codes but none worked!

$(function(){$(window).resize(titleResize);});

$(function(){$(window).resize(titleResize());});

$(window).resize(titleResize);

$(window).resize(titleResize());

any idea?

BTW it's my titleResize function:

function titleResize() {
        maxHeight = 0;
        $("div.lae-entry-text-wrap > h3").each(function(){
            titleHeight = $(this).height();
            if (titleHeight > maxHeight){
                maxHeight = titleHeight;
            }
        });
        $("div.lae-entry-text-wrap > h3").css("height", maxHeight);
    }

Try Following

$(window).resize(function(){
alert('Window Is Resized')
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

How to call a function in jQuery on window resize?, You can't declare functions that way, use it like this. <script> $(document).ready(​larg); $(window).resize(larg); function larg(){ var larghezza  The resize event occurs when the browser window changes size. The resize() method triggers the resize event, or attaches a function to run when a resize event occurs.

In Following Script your function is calling

$(window).resize(function(){
debugger
titleResize();
});
   function titleResize() {
   alert('Function titleResize() Called');
   maxHeight = 0; 
   $("div.lae-entry-text-wrap > h3").each(function(){ 
   titleHeight = $(this).height(); 
   if (titleHeight > maxHeight)
   {
   maxHeight = titleHeight; 
   } 
   });
   $("div.lae-entry-text-wrap > h3").css("height", maxHeight); 
   }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

.resize(), This method is a shortcut for .on('resize', handler) in the first and second variations, and .trigger( "resize" ) in the third. The resize event is sent to the window  .resize( handler )Returns: jQuery. Description: Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. Type: Function( Event eventObject ) A function to execute each time the event is triggered. An object containing data that will be passed to the event handler.

Try like this

$(window).on('resize', function(){ //Your code });

$(window).on('resize', function(){
    console.log('resize')
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

jQuery resize() Method, Well organized and easy to understand Web building tutorials with lots of examples The resize() method triggers the resize event, or attaches a function to run  vectorname.resize(int n, int val) Parameters: n – it is new container size, expressed in number of elements. val – if this parameter is specified then new elements are initialized with this value. Return value: This function do not returns anything. Exception: The only exception if it so happens is Bad_alloc thrown, if reallocation fails.

I have also got same issue you can use this type of code for your error

 $(window).resize( () => {
        let Width = $(window).width();
        if (Width > 910) {
            $(".navbar1").hide();
         }
    })

onresize Event, Example. Execute a JavaScript when the browser window is resized: Using the addEventListener() method to attach the "resize" event on the window object. $(window).resize() Running a function whenever the window is resized with jQuery is as simple as this: $(window).resize(function() { // do something here }); It’s possible to also assign resize() to any element but this post is specifically looking at when a window is resized. Browser Issues

How to Capture Browser Window Resize Event in JavaScript, You can simply use the addEventListener() method to register an event handler to listen for the browser window resize event, such as window.addEventListener('​resize', ) . Calling the function for the first time; displayWindowSize();; </script​> The Resize property in Excel VBA makes a range (border below for illustration only) a specific number of rows and columns larger or smaller. The Resize property always takes the top left cell of a range as the starting point. Explanation: this code line resizes Range ("A1:C4") to 3 rows and 2 columns and selects this range.

jQuery, The resize() method is an inbuilt method in jQuery which is used when the browser It is used to specify the function to run when the resize event is called. Using resizeBy is an excellent way to allow users to resize a window incrementally. For instance, you could provide them with a button that called a function when clicked. That function could execute the resizeBy method which resized the window by a small amount. Pass negative arguments to resizeBy to make a window smaller, as shown below:

Cross-browser window resize event using JavaScript/jQuery , The resize() method triggers the resize event or attaches a function to run when a resize event occurs. jQuery has a built-in method for window resize events. You can simply use the addEventListener() method to register an event handler to listen for the browser window resize event, such as window.addEventListener('resize',). The following example will display the current width and height of the browser window on resize.

Comments
  • Possible duplicate of How to call a function in jQuery on window resize?
  • Check console for error
  • there is no error in console, it seems there wont be any event listener at all!
  • May browser cached old code, So press ctrl+F5 to clear cache
  • @Mohammad no luck!
  • this will work, but when i call my function, it won't!
  • function titleResize() { maxHeight = 0; $("div.lae-entry-text-wrap > h3").each(function(){ titleHeight = $(this).height(); if (titleHeight > maxHeight){ maxHeight = titleHeight; } }); $("div.lae-entry-text-wrap > h3").css("height", maxHeight); }
  • What it means $("div.lae-entry-text-wrap > h3")