0

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);
    }
Inian
  • 80,270
  • 14
  • 142
  • 161
amir vaziri
  • 53
  • 1
  • 6

4 Answers4

1

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>
Som
  • 598
  • 3
  • 12
  • this will work, but when i call my function, it won't! – amir vaziri Sep 18 '18 at 08:56
  • 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); } – amir vaziri Sep 18 '18 at 09:12
  • What it means `$("div.lae-entry-text-wrap > h3")` – Som Sep 18 '18 at 09:24
1

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>
Som
  • 598
  • 3
  • 12
0

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>
0

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();
         }
    })
Shubham Singh
  • 147
  • 1
  • 2
  • 15