Incorporating design elements specific to an anchor tag

I have a list of links (li) with one, two, or three li elements in the ul. Each li contains an <a> tag with text or icons.

Below are some code examples:

<ul>
   <li><a href="#">prev</a></li>
   <li><a href="#">Next</a></li>
</ul>

or

<ul>
   <li><a href="#"><i class="fa-left"></i></a></li>
   <li><a href="#">Next</a></li>
</ul>

or

<ul>
   <li><a href="#"><i class="fa-left"></i></a></li>
   <li><a href="#"><i class="fa-right"></i></a></li>
</ul>

Desired Outcome

If both li elements contain an icon within the a tag, then the a element should have a border-radius of 25px. If one has an icon and one has text, or both have text, then the a element should have a border-radius of 0px.

Attempted Solution


var thumbLinkList = $('li');
var thumbLink = $('li a');
thumbLink.each(function( index,elem ){
     if($(this).find('i')){
        if($(this).parent().siblings('li').find('i')){
            $(this).css({
               'border-radius' : '25px'
              })
          }
      }
})

Answer №1

Here is a potential solution:

$('ul').each(function(index, element){
    var $unorderedList = $(element),
        hasIcons = $unorderedList.find('a > i').length > 1;
    if(hasIcons){
        $unorderedList.find('a').css('border-radius', '25px');
    }
});

Answer №2

$('ul').each(function() {
  
  if ($('i', $(this)).length > 1) {
    $('a',$(this)).css('border-radius','10px')
  }
  
});
i, a {
  display: block;
  width: 30px;
  height: 30px;
  background: red;
  overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul>
   <li><a href="#">prev</a></li>
   <li><a href="#">Next</a></li>
</ul>

<ul>
   <li><a href="#"><i class="fa-left"></i></a></li>
   <li><a href="#">Next</a></li>
</ul>

<ul>
   <li><a href="#"><i class="fa-left"></i></a></li>
   <li><a href="#"><i class="fa-right"></i></a></li>
</ul>

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

Unable to make a POST request to the application

Creating a basic web page with server.js var path = require("path"); var express = require("express"); var app = express(); var bodyParser = require("body-parser"); app.listen(8000, function() { console.log("server is listening on port 8000"); }) app.us ...

Solve problems with limitations on ng2-dnd drop zones

I successfully integrated drag and drop capabilities into my Angular 4 application using the ng2-dnd library. Within my application, I have containers that can be sorted, as well as individual items within each container that can also be sorted. My goal i ...

Issue with Django JQuery datatable ajax refresh: sorting buttons not displaying and function calls not working

Currently, I am utilizing Django along with JQuery and jquery-datatables-bs3 to generate a table for my models. The functionality allows users to add or remove table rows, which in turn creates or deletes model instances within the database. Each row featu ...

Instructions for smoothly moving back to the top (or specific anchor) from the current view using AngularJS

As I prepare to delve into the world of Angular, a burning question comes to mind. Is it feasible to create an animation that scrolls up to the top of the page or a specific anchor point when transitioning to a new view after clicking a link while scroll ...

Sending a boolean value from C# to an Angular view

This is a snippet of my code: Code written in C#: public bool isAllowed { get; set; } protected void Page_Load(object sender, EventArgs e) { isAllowed = false; } Angular controller: <script> var myApp = angular.module('m ...

Could you please clarify how to trigger the code below the layout when a data Gridview row is double clicked?

Although the HTML CODE concept can work, I am looking to apply it on my gridview table after data is binded. $(document).ready(function () { $('.clickme').click(function() { alert("Hello World"); }); }); <t ...

What are the best techniques for creating animations in AngularJS?

I've been trying to figure out how to animate in AngularJS by searching online, but I haven't found a perfect solution yet. html <span class="sb-arrow down" ng-click="hideSampleList($event)"></span> ...

Customize your Bootstrap tabs with a unique border design

I am currently working on a wizard project where the header design is inspired by the image below. I am utilizing Bootstrap-4 tabs components and the :after pseudo element method on the li element to achieve this effect. However, I am facing a challenge in ...

The switch statement within Angular returns null when using getElementById()

In my single page application, I am using ng-switch to switch between different 'pages'. One of these pages contains a modal that is opened using the following function: var modal = document.getElementById('myModal'); vm.openModal = fu ...

Select2 loading screen featuring preloaded value

Trying to populate a select2 box with instrument options on an edit profile page for a musician site. The information is pulled from the database, but I'm struggling to display the existing instrument list in the select2 box upon render - it always ap ...

The functionality of Jquery datatables seems to be faulty when navigating to the second page

While utilizing the jQuery datatables plugin, I encountered an issue where the event click function only worked on the first page and not on subsequent pages. To address this problem, I discovered a helpful resource at https://datatables.net/faqs/ Q. My ...

Saving solely the content of an HTML list element in a JavaScript array, excluding the image source

One issue I am facing is with an unordered list in HTML which contains items like <ul id="sortable"> <li class="ui-state-default"><img src="images/john.jpg">John</li> <li class="ui-state-default"><img src="images/lisa.jpg ...

Is there a way to display multiple Bootstrap 5 modals simultaneously without automatically closing the previous ones?

My current project utilizes bootstrap 5.2, which is a departure from the previous version, bootstrap 3. In bootstrap 3, it was possible to open multiple modals on top of each other, creating an overlapping effect. However, in bootstrap 5 and 5.2, the behav ...

Tips on integrating JavaScript with embedded Ruby code

I am attempting to generate a flash message that displays after a user clicks a link in my js.erb file. $('a').click(function(){ <% flash.now[:alert]= "Successfully added "%> this.innerHTML <% "to cart" %> }) M ...

Utilizing Laravel and Jquery UI for asynchronous communication with the server, passing data from a post request to

I recently constructed a basic Jquery UI slider: $("#sliderNumCh").slider({ range: "min", min: 0, max: 20, step: 1, value: 20, change : function(e, slider){ $('#sliderAppendNumCh'). ...

Switching to version 2 of date-fns: Not a Number

I am currently in the process of updating the date-fns module from version 1 to version 2. Prior to the update, the following helper method functioned as expected: const { format, parseISO, differenceInSeconds } = require("date-fns"); const new ...

Impact of Jquery on dropdown menus in forms

Currently, I have a script for validating form information that adds a CSS class of .error (which includes a red border) and applies a shake effect when the input value is less than 1 character. Now, I also need to implement this validation on various sel ...

The webpage's Document Object Model fails to refresh following a JavaScript modification

I have encountered an issue with a sample webpage where I am attempting to set the wmode of all YouTube elements on the page to "transparent." When inspecting the page using Chrome, I can see that my JavaScript code is functioning properly. However, the b ...

Confirm the 'background-image' CSS URL with Cypress

Is it possible to verify the status code '200' of a CSS background-image URL using Cypress for image loading validation? Any suggestions on how to accomplish this? it('Validate displayed images',() => { cy.get('.logo'). ...

Effortlessly Transition to Full Screen with Div Expansion on Click

I'm currently working on creating a smooth transition for a div to expand fullscreen when clicked. My goal is to achieve a similar effect as the case studies on this website: Although my code can make the div go fullscreen, there's an issue with ...