Show a modal with jquery taking a reference class

0

Good morning I am trying to show a modal when loading a page taking a reference class, what I want to achieve is to show the modal in only one page and in the others not what I'm thinking about is taking a reference class and show the modal if that class exists on the page

$(document).ready(function () {
      document.getElementById('hoteles').load( function() {
      //$(window).load(function(){
         $('#myModal').modal('show').delay(30000).fadeOut('fast');
      });
)};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

I was trying to do it like that but it obviously gives me error

    
asked by Carlos Vargas 07.09.2017 в 18:07
source

1 answer

0

You should not mix JavaScript with jQuery, try doing something like:

$(function () {
    if ($('#hoteles').length) { // o, si buscas una clase, '.hoteles'
      $('#myModal').modal('show').delay(30000).fadeOut('fast');
    }
});

In this way, if there is no element with the id (or class) hoteles , it simply will not do anything, but it will not give an error.

    
answered by 07.09.2017 в 18:17