Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8141411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:29:54+00:00 2026-06-06T12:29:54+00:00

I have a Jquery Mobile collapsible set , which can have any number of

  • 0

I have a Jquery Mobile collapsible set, which can have any number of “drawers”. JQM assigns corner like this:

  collapsibleHeading.find("a").first()
      ...
      .add( ".ui-btn-inner", $el )
         .addClass( "ui-corner-top ui-corner-bottom" )

I want to add a horizontal-option to the collapsible, so it also works like a tab-box. I have the CSS all ready but the corner in a single statement are difficult…

I need to check for direction, which I’m doing like this:

 (o.directon) == true/false

This is what I have:

// predefine classes for HORIZONTAL(first,last,rest) and VERTICAL
baseCorners = o.direction == "horizontal" ? [ "ui-corner-tl", "ui-corner-tr", "" ] : ["ui-corner-top", "ui-corner-top", "ui-corner-top"],
toggleCorners = o.direction == "horizontal" ? [ "ui-corner-bl", "ui-corner-br", "" ] : ["ui-corner-bottom","ui-corner-bottom","ui-corner-bottom" ],

So now I can assign baseCorners and toggleCorners without worrying about direction.

My problem:
How can I add a check/filter for first/last/remaining collapsibles, so that I can run this in one statement like so:

  collapsibleHeading.find("a").first()
      ...
      .add( ".ui-btn-inner", $el )
         .addClass( "if-first" ? baseCorners[0] : "elseif-last" ? baseCorners[1] "else" baseCorners[2] + "same for toggleCorners" )

Question:
I’m lost… any idea if this is at all possible? Thanks for help.

EDIT:
This is what I have now:

.filter(":first")
    .add( ".ui-btn-inner", $el )
        .addClass( baseCorners[0] + toggleCorners[0] ).end()
.filter(":last")
    .add( ".ui-btn-inner", $el )
        .addClass( baseCorners[1] + toggleCorners[1] ).end()
.not(':first').not(':last')
        .add( ".ui-btn-inner", $el )
            .addClass( baseCorners[2] + toggleCorners[2] );

Not sure this is the most feasable solution though

SOLUTION:
Thanks for helping everyone. This is how I did it in then end. Once I had the proposed solution set up, I found out, that JQM runs the script for every element, so I could not use a loop, because on every run, there is only 1 element to loop through.

This way it works:

 // if not horizontal, I always assign the same class
 baseCorners = o.direction == "horizontal" ? [ "A", "B", "C" ] : ["D", "D", "D"],
 toggleCorners = o.direction == "horizontal" ? [ "E", "F", "G" ] : ["H","H","H" ],
 // get position of current element and calculate trigger
 collIndex = $('div:jqmData(role="collapsible-set") div:jqmData(role="collapsible") h3').index(collapsibleHeading),
 collTrigg = collIndex == 0 ? 0 : collIndex == $('div:jqmData(role="collapsible-set") div:jqmData(role="collapsible")').length-1 ? 1 : 2;

With this setup, the first element always gets index 0, the last always index 1 and everything in between index 2, so I’m staying flexible regarding the number of elements in between.

Then it’s just:

 $el.add( ".ui-btn-inner", $el )
      .addClass( baseCorners[collTrigg] + toggleCorners[collTrigg] );

Nice!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:29:57+00:00Added an answer on June 6, 2026 at 12:29 pm

    This should be the same. It’s not like it’s a lot less code, but it avoids repetition and should therefore be easier to maintain.

    selection.each(function(i,e) {
    
        var el = $(e),
            index = i===0 ? 0 :
                i===selection.length-1 ? 1 : 
                2;
    
        el.add( ".ui-btn-inner", $el )
            .addClass( baseCorners[index] + toggleCorners[index] );
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery Mobile accordion menu set up like: <div class=subCat data-role=collapsible> <h3
I have a jQuery Mobile accordion menu set up like: <div class=subCat data-role=collapsible> <h3>Subcategory
I have the following jquery mobile code: <div data-role=collapsible> <h3>I like to read a
I have a jquery mobile list. This list is populated with data. I want
I have been working with jQuery mobile 1.0.1. I have a page which drills
I have modified jquery mobile a little so a collapsible with data-type=horizontal converts into
I have a single page jquery mobile application in which there are few parent
I'm having an issue with a jQuery Mobile collapsible div not shrinking any narrower
I have a JQuery Mobile app. This app needs to hit a remote web
I have a JQuery Mobile app. This app has a page with a select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.