When trying to display the orientation event in Jquery Mobile, an error message appears stating "Uncaught ReferenceError: css is not defined"

Creating a basic Bootstrap 3 site, I've set up a full-width header with a Bootstrap Carousel showcasing three images. To handle different viewport widths, I added a media query to switch between image sets based on width. Here's the code snippet for HTML and CSS:

<!-- Full Page Image Background Carousel Header -->
<header id="carousel-intro" class="carousel slide page-scroll ">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#carousel-intro" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-intro" data-slide-to="1"></li>
        <li data-target="#carousel-intro" data-slide-to="2"></li>
    </ol>

    <!-- Wrapper for Slides -->
    <div class="carousel-inner wow bounceIn" data-wow-duration="2s">
        <div class="item active">
            <div id="carousel-intro-img-1" class="fill"></div>
        </div>
        <div class="item">
            <div id="carousel-intro-img-2" class="fill"></div>
        </div>
        <div class="item">
            <div id="carousel-intro-img-3" class="fill"></div>
        </div>
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-intro" data-slide="prev">
        <span class="icon-prev"></span>
    </a>
    <a class="right carousel-control" href="#carousel-intro" data-slide="next">
        <span class="icon-next"></span>
    </a>

    <a id="scroll-link" class="page-scroll " href="#chi">
        <i class="fa fa-angle-double-down white animated infinite pulse"></i>
    </a>
</header>

/*Header section*/
.carousel,
.item,
.active {
    height: 100%;
}
.carousel-inner {
    height: 100%;
}
.carousel-indicators{
    visibility: hidden;
}
.icon-prev,.icon-next{
    visibility: hidden;
}

/*Setting carousel image*/
@media screen and (max-width: 991px){
    #carousel-intro-img-1{
        background-image:url(../img/intro-tablet/intro1g.jpg);
        background-repeat: no-repeat;
    }
    #carousel-intro-img-2{
        background-image:url(../img/intro-tablet/intro2g.jpg);
        background-repeat: no-repeat;
    }
    #carousel-intro-img-3{
        background-image:url(../img/intro-tablet/intro3g.jpg);
        background-repeat: no-repeat;
    }
}
@media screen and (min-width: 992px){
    #carousel-intro-img-1{
        background-image:url(../img/intro-desktop/intro1g.jpg);
        background-repeat: no-repeat;
    }
    #carousel-intro-img-2{
        background-image:url(../img/intro-desktop/intro2g.jpg);
        background-repeat: no-repeat;
    }
    #carousel-intro-img-3{
        background-image:url(../img/intro-desktop/intro3g.jpg);
        background-repeat: no-repeat;
    }
}
.fill {
    width: 100%;
    height: 100%;
    background-position: center;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    -o-background-size: cover;
}

To update the images when switching to landscape view, jQuery mobile was included:

script src="js/jquery.mobile.custom.min.js"></script>

The following script was then implemented:

 $(window).bind('orientationchange resize', function(event){
  if(event.orientation) {
        if(event.orientation == 'portrait') {
             $('#carousel-intro-img-1'),css('background-image', 'url(../img/intro-tablet/intro1g.jpg)');
             $('#carousel-intro-img-2'),css('background-image', 'url(../img/intro-tablet/intro2g.jpg)');
             $('#carousel-intro-img-3'),css('background-image', 'url(../img/intro-tablet/intro3g.jpg)');
          } else 
        if (event.orientation == 'landscape') {
            $('#carousel-intro-img-1'),css('background-image', 'url(../img/intro-tablet-landscape/intro1g.jpg)');
            $('#carousel-intro-img-2'),css('background-image', 'url(../img/intro-tablet-landscape/intro2g.jpg)');
            $('#carousel-intro-img-3'),css('background-image', 'url(../img/intro-tablet-landscape/intro3g.jpg)');
          } 
        }  //event orientation
        else {}
  });

However, an error occurs specifically for dimensions below 768px, indicated as Uncaught ReferenceError: css is not defined. This issue does not affect larger dimensions where everything functions correctly.

Why is this happening?

Upon inspecting the Chrome log console, it is evident that the 'css' attribute is causing the error message. This problem seems isolated to smaller viewport sizes.

Answer №1

To update your JavaScript code, simply modify the following:

$('#carousel-intro-img-1'),css

to

$('#carousel-intro-img-1').css

Make sure to replace the comma with a period in all occurrences.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporate HTML content into a jQuery tab on Codeigniter using jQuery AJAX

I have encountered an issue where I am unable to load a piece of HTML code (a form containing client data) into jQuery tabs using jQuery AJAX. Despite trying different methods like .load(), .append(), and .html(), I am unable to load a simple HTML form int ...

Limiting the input to a single-level bullet point list is possible with jQuery if desired

Looking for a way to let users create a single-level bullet list without needing knowledge of HTML formatting. Need a solution that won't mess up the formatting if auto-formatted. Considering using a wysiwyg editor, but it has to support creating bull ...

Preventing div contents from shrinking with changing screen sizes

I am currently working on creating a portfolio website similar to this one. Check out the Website Here Typically, when the screen size is reduced to less than half of the full width, the content of a website tends to be hidden rather than shrinking. Howe ...

Failed to input data into MySQL database's dynamic field

I have encountered an issue while trying to enter dynamic fields into a MySQL database, and I am struggling to figure out the cause of the problem. Below are both the HTML and PHP files provided; I would greatly appreciate any assistance in identifying and ...

Problem with jQuery ajax redirection

I have been using the script below to dynamically load pages on my website: var xhr; function Ajax(afile,adiv,arun,loader) { // Loading info if(loader==null) { gi("loaderdiv").style.display='inline'; } // Process Ajax var htm = afile.split(&apo ...

Transform @Html.PagedListPager from MVC into a structured list using Ul and LI elements

I'm currently using a paging code in my view. How can I convert this into "ul & li" tags? @Html.PagedListPager(Model, page => Url.Action("DisplayTTs", "TTCreator", new { page = page, SearchTT = ViewBag.searchTxt })) ...

How can I utilize Handlebars and a JSON API call to effectively transfer data from an array response and display it within a Handlebars modal?

$("#searchMovieBtn").click(() => { const movieSource = $("#movie-template").html(); const movieList = Handlebars.compile(movieSource); const movieSearch = $("#addMovie").val(); console.log(movieSearch); queryURL = `https://ap ...

PHP script is not successfully receiving the Ajax post request that is

As a newcomer to the world of php and ajax, I am facing a challenge in passing a variable from jquery to a php page loaded within a modal window. My php script fetches table information for multiple users. Next to each user's name, there is an edit b ...

Create dynamic cells for CSS grid using JavaScript

I have been manually generating grid cells in a specific pattern by copying and adjusting <div> elements. Although this method works, I am interested in creating an algorithm that can automatically generate the desired layout. The left box in the exa ...

Using arrays to pass parameters in JavaScript

I have multiple sliders that require the same set of parameters to be passed to each one. My understanding is that I need to use an array for this purpose. However, as a JavaScript novice, I am unsure of the correct way to implement it. The parameters lo ...

What exactly does the jquery ajax success callback cover?

Is the value of testvar in function AjaxRequest going to increase on success? function AjaxRequest(){ var testvar = 0; for(i=0;i<d.length;i++){ $.ajax({ success: function(a){ testvar++; } ...

There is an irritating 5px gap between the divs in the Avada WordPress theme. While using margin-top: -5px helps to reduce this spacing, padding-top: -5

Struggling to remove a persistent 5px whitespace on my website eternalminerals.com See the issue highlighted in this screenshot: Trying to eliminate the whitespace by adjusting margins in Google Chrome, but unable to apply styles to Avada shortcodes: &l ...

Experience the auditory bliss with Javascript/Jquery Sound Play

I am creating an Ajax-driven application specifically for our local intranet network. After each response from my Ajax requests, I need to trigger a sound in the client's browser. I plan to store a sound file (mp3/wav) on our web server (Tomcat) for ...

Obtain HTML tags from RSS CDATA section

Is there a way to extract HTML tags from a CDATA tag in an RSS feed? I have utilized a basic jQuery function to retrieve the JSON object from the RSS, below is my code: $.get("someURL", function(data) { console.log('InGet'); ...

The Ajax cross-domain request is not reaching the success callback function

Greetings! I've recently developed a Web application using Spring MVC. Within this application, there is a method that retrieves JSON data. When I invoke this method, it successfully returns the desired JSON data. However, when attempting to call the ...

Activate current event on newly added elements

Is it possible to have both blur and keypress(13) trigger the same action on an appended element? I thought using trigger() would work, but it's not. Hopefully, I'm just missing something obvious. $(document).ready (function() { $("#btn").cli ...

Waypoint function malfunctioning when overflow:hidden is applied

CodePen If you exclude the overflow property from the CSS selector .wrapper in the CodePen example, the waypoints functionality will work properly. However, it does not function correctly when using the overflow set to hidden either horizontally (x) or ...

Retrieve information from the server (using asp.net) using Java Script and store it in the local storage of the client device

I am receiving a JSON object from the server-side, but I have been struggling to save it in LocalStorage. When I check FireBug, this is how it appears: If you are having trouble viewing the images clearly, try opening them in a separate page by right-click ...

The powerful combination of Ajax and Django creates a dynamic Like button

Encountering difficulties while trying to implement a basic like button feature. Despite following various tutorials, clicking on the Like button does not yield any action. See below: models.py class Comentario (models.Model): titulo = models.CharFie ...

Is it possible to conceal any spans that are in close proximity to the cursor when hovered over?

Currently, I am working on a project that involves multiple spans placed side by side, with each span containing a letter of the text. My aim is to create a functionality where hovering over one of these spans will not only hide that particular span but al ...