jQuery Show/Hide Not Working Properly

I'm attempting to showcase one Tweet at a time and have it rotate through different tweets. I'm facing an issue where it works correctly on one type of page, but not on the other. Could this be due to a CSS precedence rule overriding the functionality?

Here is the structure of the HTML:

<div class="twitterFeed">
    <p>Tweet here</p>
    <p>Tweet here</p>
    <p>Tweet here</p>
    <p>Tweet here</p>
    <p>Tweet here</p>
</div>

And here is the JavaScript code being used:

var currentTwitterItem = 4;
NextTwitterItem();

setInterval( NextTwitterItem, 8000);

function NextTwitterItem() {

    currentTwitterItem++;

    if (currentTwitterItem >= 5) {
        currentTwitterItem = 0;
    }

    $(".twitterFeed p").hide();
    $(".twitterFeed p:eq(" + currentTwitterItem + ")").show();

}

Answer №1

let currentTwitterItem = 0;
nextTwitterItem();

setInterval( nextTwitterItem, 8000);

function nextTwitterItem() {
    $(".twitterDiv").each(function(){
        $(this).find(".twitterFeed p").hide();
        $(this).find(".twitterFeed p").eq(currentTwitterItem).show();
    })

    if (currentTwitterItem >= 5) {
        currentTwitterItem = 0;
    }
    else
    {
        currentTwitterItem++;
    } 
}

Check out the updated Fiddle!

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

Mobile Safari on iOS devices is known for its capability to overlay HTML5 <video> on top of everything

Although a similar question was asked 6 years ago without any answers, I am currently facing the same issue. Problem: The <video> tag in my Angular/Ionic application overlaps my image and two buttons in iOS Mobile Safari - no matter what I try! It ...

Incorporating an HTML image into a div or table using jQuery

I am a beginner in using JQuery within Visual Studio 2013. My question is how to insert an img tag into a table or div using JQuery? For example, I have a div and I would like to generate an image dynamically using JQuery. Or, I have a dynamically create ...

How can the cross-domain AJAX form submission be achieved?

I am currently utilizing jQuery along with the jQuery form plugin Within the jQuery form plugin, there is a method called ajaxSubmit. This method allows you to submit a form via ajax and receive a response. I find it intriguing how this process works even ...

Failure to execute Ajax request when searching for a query

My personal GitHub profile viewer React application allows you to search for a profile by username. By default, my own GitHub username is provided on the landing page. However, when trying to search for another user, my ajax call is not functioning properl ...

Is there a problem with the layout or indexing?

My website features a div that animates in using a jQuery click function, appearing over other divs that have animated in on $(document).ready(). Strangely, this div shows up behind the others only on the home page of my website and not on any other pages, ...

Is it possible to utilize $(this) within the $.post() function?

I seem to be having trouble accessing $(this) from inside the $.post section. It works perfectly fine outside of it. Here is the JavaScript code: $('.idea').each(function(){ var title = $(this).html(); $.post("votes.php", { t ...

Text Parallax Effect

For my website, I am interested in incorporating a unique parallax effect. Instead of just fixing a background image and allowing scrolling over it, I want to apply this effect to all of the content on my site. The website consists of a single page with m ...

What is the best way to retrieve the ID of the input element using a jQuery object?

After submitting a form with checkboxes, I retrieve the jQuery object containing the checked input elements. var $form = $(e.currentTarget); var $inputs = $form.find("input.form-check-input:checked") Here is an example of how the inputs are stru ...

Pressing a button is a way to select a specific form

I'd like to create a clickable button that can direct users to the form section on the same page. <button type="button" class="btn btn-primary btn-sm"> Go to Form Section </button> ... <form id="form1"> <div class="form-g ...

Applying a Webkit Scroll Bar to a specific element on the webpage

I've been attempting to apply the Scroll Bar webkit styling to a particular element but haven't had any success. Despite searching extensively, I have come across 2 threads on Stack Overflow that do not provide a solution. Most of the available ...

Navigating through content on a screen can be accomplished in two

Is it feasible to incorporate both horizontal and vertical scrolling on a website using anchor tags? I recently created a website with horizontal scrolling for each main page. Within some of these main pages, there are subsections that I would like to hav ...

Slowly revealing sticky navigation with slideDown animation using JQuery

Here is the code for a .JS file: $(document).scroll(function (){ var menuheight= $('header').height(); var y = $(this).scrollTop(); if (y>(menuheight)) { $('.menu_nav_features').addClass ...

I am looking to enhance my JSON output using JavaScript

My JSON output appears as follows: {"intent":"P&P_Purchase","value1":{"date1":"30-Dec-19","prd_desc":"NEEM UREA OMIFCO (45 KG)","qty":"18MT","inv_no":"NRKT07003160"},"value2":{"date1":"25-Dec-19","prd_desc":"NEEM UREA IMP (45 KG)","qty":"18MT","inv_no ...

Animations of bezier curves created with Three.js

UPDATED: SOLUTION FOUND I am in need of guidance on how to create animation for the movement of points along a curve to simulate string motion in 3D while keeping performance in mind. Imagine multiple strings between two points, for example. Check out t ...

Font rendering issue in Chrome extension

I have been diligently following various tutorials on incorporating a webfont into my Chrome extension, but unfortunately, none of them seem to be working for me. Despite all my efforts, the font remains unchanged and still appears as the default ugly font ...

Attempting to align a header and an unordered list side by side

I'm feeling a bit lost here and I've been doing my best to find a solution online, but no luck so far. What I need help with is getting my header element and unordered list to appear on the same line without losing their respective margins. ...

In order to utilize Next.js with pkg, you must enable one of the specified parser plugins: 'flow' or 'typescript'

Utilizing next.js with the pkg in my project, following the steps outlined in this tutorial, I encountered an error when running the pkg command: > Error! This experimental syntax requires enabling one of the following parser plugin(s): 'flow, t ...

Incorporating a spectrum of hues into an HTML document

As a beginner in HTML, I recently stumbled upon a website (YT video) showcasing a stunning array of colors on buttons. You can check it out here: https://www.youtube.com/watch?v=OPaLnMw2i_0 I'm curious if these colorful designs can be applied to text ...

Using setState in an external function: A step-by-step guide

import Request from 'superagent'; const fetchApi = () => { let apiUrl = '/* URL */'; return Request.get(apiUrl).then((response) => { this.setState({ data: response.body }); }); } export d ...

Tips for setting the style of child components in a ReactJS project with CSS modules, classNames, and JSX syntax

Currently in the process of setting up a project using React JS and I am interested in incorporating auth0 for authentication purposes, along with potentially integrating some serverless functions. auth0 conveniently offers a pre-made "seed" project at ht ...