-1

I have a simple div with basic content...

<div id="slide"> ... </div>

The following code works in FireFox but not in Chrome. I tried accessing the .css ("width") and other properties as well with the same result.

$(window).resize(function() {
  if( $(this).width() < 900) {
    alert( $("#slide").html() );
  }
});

Any idea why this isn't working in Chrome? One interesting thing is this does work in both...

$(window).resize(function() {
  if( $(this).width() < 900) {
    $("#slide").hide();
  }
});

My end goal is to access/change a child element in the div, but that wasn't working, so I tried to the access to the div itself for a sanity check...and no luck in Chrome.

  • I cannot reproduce your issue, see [JS Bin](https://jsbin.com/comunamopa/edit?html,js,console,output). – Michał Perłakowski Mar 04 '16 at 16:48
  • Are you sure you haven't checked "prevent additional dialogs" checkbox in Chrome when the alert first popped up? Try clearing browser cache and settings. Also avoid using `alert()`, use `console.log()` instead. http://stackoverflow.com/questions/19640361/re-enabling-window-alert-in-chrome – Victor Levin Mar 04 '16 at 16:54
  • What version of chrome are you running? Have you tried updating? – Lewis Mar 04 '16 at 17:07

2 Answers2

0

The following works fine for me...

Chrome Version 48.0.2564.116 (64-bit)

var slide = $("#slide");

$(window).resize(function(){
    if($(this).width() < 900){
       alert(slide.html());
    }
})

Js Fiddle: https://jsfiddle.net/e28Lnv5t/1/

Lewis
  • 3,479
  • 25
  • 40
0

The following works for me

HTML:

<p>Minimize the screen and look different</p>

<div id="slide">TEST</div>

CSS:

#slide{
  border: solid thin #bebebe;
}

JS

$(window).resize(function(){
    if($(this).width() < 900){
    $("#slide").hide();
  }
})