username username - 1 year ago 121
Javascript Question

javascript remove all elements :Uncaught SyntaxError: Unexpected identifier

This type of questions has been asked alot in this site, but i don't understand why this happens.
I want to write a script that removes all elements with class "not_imp_msg" and i did this


Actually this is for flash message in laravel and in my flash.blade.php

@foreach($flash as $flash_message)
@if(isset($flash_message['status']) && $flash_message['status'] != null)
<div class="box box-{{$flash_message['class']}} box-solid">
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
<div class="box-body">
<div class="box box-{{$flash_message['class']}} box-solid not_imp_msg">
<div class="box-body">


This gives me the error after 2 seconds but all elements slides up as soon as documents load. Should it not wait for 2 seconds. I can't understand why.

Answer Source

Try passing anonymous function, as setTimeout is expecting function name or anonymous function:

$(document).ready(function() {
  setTimeout(function() {
  }, 2000);
.not_imp_msg {
  background-color: #ddd;
  border-top: 1px solid white;
  height: 50px;
  display: none;
<script src=""></script>
<div class="not_imp_msg"></div>
<div class="not_imp_msg"></div>
<div class="not_imp_msg"></div>
<div class="not_imp_msg"></div>
<div class="not_imp_msg"></div>

Side notes

If you want to remove elements, than use callback function of slideUp(callback) to .remove elements.

.slideDown will reveal elements, .slideUp will collapse elements, but they will still be presented in DOM with 0px height

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download