Verify if the second list item contains the "current" class

When displaying a list of blog items on the blog page, I am using grid-column: 1 / -2;. In the first row, the first blog item spans two columns while the second and subsequent rows display three items in each row. This setup works well, but when moving to the second or third page, the first row remains the same. I only want the latest blog to stretch across two columns in the first row, with three columns displayed in the first row on all other pages.

To work around this issue, I found a solution in the pager control by checking if the class current is present in the second element.

My question now is, how can I use jQuery to detect if the UL LI element has the class current in the second position? If it does, I want to change the grid-column: 1; to display three columns in the first row on the 2nd, 3rd, 4th, or 5th pages.

https://i.stack.imgur.com/aeI6Q.png

The code for my pager control is as follows:

<ul id="ContentPlaceHolder1_PagerControl1_pnlPager" class="nav-pager">
<li><a id="ContentPlaceHolder1_PagerControl1_-1" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$PagerControl1$-1','')"> « </a></li>
<li><a id="ContentPlaceHolder1_PagerControl1_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$PagerControl1$0','')">1</a></li>
<li class="current"><span id="ContentPlaceHolder1_PagerControl1_39e9e1f727784cce80f1a3b5e6e43ac0">2</span></li>
<li><a id="ContentPlaceHolder1_PagerControl1_2" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$PagerControl1$2','')">3</a></li>
<li><a id="ContentPlaceHolder1_PagerControl1_26" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$PagerControl1$26','')"> » </a></li>
</ul>

I attempted the following code for testing purposes to see if it would work. This simple code, where I try to change the background color, did not work:

if($("ul li").hasClass('current')) {
$(this).css("background-color", "yellow");
}

Answer №1

Resolved: I utilized jQuery to showcase two items in the first row of the initial page, and three rows on all pages.

Cascading Style Sheets (CSS):

.article:nth-child(1) {
   grid-column: 1;
}

jQuery Section

$(document).ready(function () {
        var counter = 1;
        $('.nav-pager li').each(function () {
            if ($(this).hasClass("current")) {
                if (counter == 2) {
                    //  alert("Found : " + counter);
                    $(".article:nth-child(1)").css("grid-column", "1 / -2");
                  
                }
            }
            counter = counter + 1;
        });
    });

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

Error message: Jquery parameter exceeds character limit

What is the length of data in jQuery? I have not added it to the database. How can I add it to the database?? function saveDataInDatabase(ligId, ligName, ligGroupId, regionName, takimId, tarih, saat, kod, mbs, karsilasma, oranSayisi, live, macSonucu, ci ...

Troubleshooting CSS Carousel Navigation Problems

{% extends 'shop/basic.html' %} {% load static %} {% block css %} .col-md-3 { display: inline-block; margin-left:-4px; } .carousel-indicators .active { background-color: blue; } .col-md-3 img{ width: 227px; ...

The Angular service/value is failing to retrieve the updated variable from the $(document).ready() function

Currently, I'm facing an issue with my Angular service/value. It seems to be grabbing the original variable instead of the new one that is supposed to be inside $(document).ready(). Here's the relevant code snippet: var app = angular.module("app ...

Styling JQuery UI dialog with an external CSS file

I found a helpful resource at http://jqueryui.com/demos/dialog/ $('#add_remarks').click(function(){ $( "#remark-form" ).dialog( "open" ); }); $( "#remark-form" ).dialog({ autoOpen: false, modal: true, buttons: { 'Add ...

Tips for effectively making REST requests from a ReactJS + Redux application?

I'm currently working on a project using ReactJS and Redux, incorporating Express and Webpack as well. I have successfully set up an API and now need to figure out how to perform CRUD operations (GET, POST, PUT, DELETE) from the client-side. Could so ...

Top way to include an HTML and javascript file in an Ext.Panel within Sencha Touch

My main goal is to efficiently include external HTML files and display them on an Ext.Panel in Sencha touch 2.3 by creating a wrapper module for the HTML file that can be instantiated using xtype, with an external Javascript file for event handling. Updat ...

Implementing a delay in a CSS menu design while still ensuring compatibility with browsers that do not support JavaScript

I currently have a three-tiered menu that relies on :hover and is controlled by css alone. I am now looking to introduce a slight delay to the hovers, which means transitioning my css :hovers to a .hover class and incorporating jQuery. My concern is whet ...

Display scrollable content at the bottom

I am currently working on creating a chat application using JavaScript (AngularJS without jQuery) and I am wondering if it is possible to have a scrollable div load to the bottom automatically. While I am familiar with the scrollTo JS property, I do not f ...

What steps can be taken to avoid the appearance of the JavaScript prompt "Leaving site"?

Hi there, I'm currently trying to find a way to remove the Javascript prompt/confirm message that asks "Do you want to leave this site?" like shown in this link: The issue I am facing is that when a modal opens and the user clicks on "YES", it redire ...

JQuery Label Click Problem with Selecting All Check Boxes

I'm attempting to create a SELECT ALL checkbox that can be clicked on the label itself. Currently, only alert statements are triggered when clicking the label. On the right side under Asset Types, there is a checkbox that, when checked, selects all o ...

Sometimes jQuery may require multiple executions with just one click

Content of index.php <script type="text/javascript" src="//<?php echo $_SERVER["SERVER_NAME"];?>/javascript/jquery-1.10.2.min.js" ></script> <script type="text/javascript"> $(document).ready(function() { $( document ).on( 'c ...

Incompatibility Issue with Ajax Request on iPad 1 (iOS 5.1.1)

Having an issue with reloading content on my iPad web app. The get request works fine in the browser, but I'm experiencing trouble in Safari on the iPad 1 (iOS 5.1.1). Any suggestions on how to fix this? <script type="text/javascript"> ...

Error encountered using jQuery $.post: TypeError - e.type is not a valid function

I'm currently in the process of developing a feedback script specifically for the ZetaBoards forum software. My approach has been to create a $.post function, but when I attempt to submit the form by clicking the submit button, all I get in return is ...

"Exploring the world of WordPress: Developing plugins with Ajax for database integration and admin email

Currently, I am in the process of developing my first Wordpress contact us plugin for a website project. Here is the progress I have made so far: The plugin shows up in the plugin list on the WP dashboard Upon activation, a new table is created in the d ...

Ensuring one div remains in a fixed position relative to another div

I'm struggling to keep my two white divs aligned in relation to the black div in the center. They need to maintain the same distance from the black div even when the page is resized. #halvfjerds { width: 100%; height: 1050px; background-color ...

Clones are made sortable instead of arranging them in a specific order

I have a list that can be sorted with some customizations. However, I am facing an issue where the items in the list get duplicated every time I try to sort them. When I pull one item to sort it, another copy gets added automatically. I am struggling to u ...

Learn how to fetch the attribute value using JQuery

In my current HTML, generated dynamically via JavaScript, I have the following code snippet: <div lang="en" id="s7_videoview_playPauseButton" class="s7playpausebutton" data-description="Scene7ComponentHolder" data-component="PlayPauseButton" state="up" ...

CSS Flexbox: Achieving Perfect Alignment for a Responsive Hamburger Navbar

This is a specific inquiry that requires your attention To begin, kindly execute the code in fullscreen mode Inspect the code and adjust it to fit within a mobile width (there seems to be an issue with responsiveness) Next, open the hamburger menu As show ...

Designing a unique CSS border for custom list item bullets

I'm currently exploring the possibility of implementing a CSS border around an image that I have imported as a custom bullet for my list items: ul { list-style: none; margin-right: 0; padding-left: 0; list-style-position: inside; } ul > ...

What is the process for collapsing Kendo Grid headers?

My current task is rather unusual. I have been tasked with collapsing all data rows of a Kendo grid to its header. While I am familiar with collapsing to groups, this particular requirement seems quite challenging. Below is the proposed design for the Ken ...