Utilizing JQuery to differentiate a single element within a group of elements

As a beginner in the world of jquery, I am attempting to assign a font awesome icon star (fa-star) to differentiate between admins and regular members within the group members bar. The usernames have been blurred out for privacy reasons, but my goal is to use jquery to place the font awesome star icon next to the admin blogs. Out of the two displayed blogs, only the bottom one (with the blue Tumblr icon) belongs to an admin. View the member bar image here.

I made an initial coding attempt but feel a bit lost. I know this can be achieved because I've seen it on other Tumblr themes using jQuery classes and CSS. I'm just struggling to make it work as nothing is showing up so far.

Here's my somewhat flawed jQuery script:

<script>
$(document).ready(function(){
    $("title").attr(".admins");
    $(".actualmember").addClass(".admins");
});
</script> 

The CSS:

<style type="text/css">
.actualmember {
display:block;
margin-top:15px;
text-transform:uppercase;
font-weight:bold;
margin-left:50px;

}

.admins {
position:relative;
}

.admins:before {
content: "\f005";
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
}
</style>

The HTML: {block:GroupMembers}

<h2>Members</h2>

{block:GroupMember}<div class="members">
<img src="{GroupMemberPortraitURL-40}">  
<a class="actualmember" href="{GroupMemberURL}" title="{GroupMemberTitle}">
{GroupMemberName}<i class="fas fa-star" title="admins"></i></a>
</div>

{/block:GroupMember}
</div>
{/block:GroupMembers}

Answer №1

I used the title attribute to target the element and then added the fa-star class. I hope this solution is helpful!

$(document).ready(function() {
  $("[title='admins']").addClass("fa-star");
});
.actualmember {
  display: block;
  margin-top: 15px;
  text-transform: uppercase;
  font-weight: bold;
  margin-left: 50px;
}

.admins {
  position: relative;
}

.admins:before {
  content: "\f005";
  font-family: FontAwesome;
  font-style: normal;
  font-weight: normal;
  text-decoration: inherit;
}
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>Mesmbers</h2>

<div class="members">
  <img src="https://lh6.googleusercontent.com/-IrsYX1O4No0/AAAAAAAAAAI/AAAAAAAAAKg/UQlwakOCMoA/photo.jpg?sz=64">
  <a class="actualmember" href="{GroupMemberURL}" title="{GroupMemberTitle}">
    <i class="fas"></i></a>
</div>
<div class="members">
  <img src="https://lh6.googleusercontent.com/-IrsYX1O4No0/AAAAAAAAAAI/AAAAAAAAAKg/UQlwakOCMoA/photo.jpg?sz=64">
  <a class="actualmember" href="{GroupMemberURL}" title="{GroupMemberTitle}">
    <i class="fas" title="admins"></i></a>
</div>

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

Launching a Node.js script with pm2 and implementing a delay

Utilizing the amazing pm2 package to maintain the longevity of my node.js applications has been extremely helpful. However, I have encountered a problem that I am unsure how to resolve. One of my applications involves multiple scripts, a server, and sever ...

Make sure to insert the Google Conversion Tracking code either after submitting the form or clicking

Need help with adding Google conversion tracking code after successful AJAX call. I can't simply hide the code in a div and change its display property to "none" because Google will track it, so I have to inject it after the AJAX call. ...

Steps for launching a browser using Capybara and Selenium

I am completely new to utilizing Capybara and have not had any experience with Selenium in the past. Currently, I am working on a Ruby on Rails project on MacOSX and encountering an issue where the browser window does not open when I execute my test. My te ...

Avoiding the use of destructuring for undefined values in JavaScript can be achieved by implementing

Upon receiving the response registryReportSettings from the server: this.getRegistrySettings(registry.Id).subscribe((registryReportSettings: { extended: ReportPropertiesRequest }) => { const { objectProperties, reportProperties, textProperties } = reg ...

The header that sticks on scroll is annoyingly blocking the content

I managed to create a sticky on-scroll header/navigation bar successfully. Here is how it looks now However, I encountered an issue. When it reaches the top, it automatically 'covers' the top part of my content, which has text on it, and I don& ...

Is there a way to convey a transition MUI property from a parent component to its child component in React?

My current setup involves a parent component with a button that triggers the opening of a snackBar from MUI (child component) upon click. To enhance the user experience, my teacher suggested adding a transition effect to the onClick event so that the snack ...

The nested promise.all function is executing synchronously instead of asynchronously as anticipated

Within the nested Promise.all section of my NodeJs script, I believe there is an error. The script is designed to process multiple .csv files within a directory, creating a database record for each row. If a row fails processing, it is added to a list of f ...

Activate the HTML drop-down option upon selecting the radio button, or the other way around

I'm attempting to accomplish a task. Below is the code snippet I am working with: <form> <input type='radio' name='radio_flavour' checked/>Unique flavour<br/><input class='double-flavoured' type=&apo ...

Select the date that is three months from now using the datetimepicker feature of Bootstrap

I have two datetimepicker fields for selecting a start date and end date. I am utilizing the eonasdan datetimepicker plugin for Bootstrap. I am trying to set the range from the current date up to 3 months ahead. However, when I use maxdate:'+90d&apo ...

The `overflow:auto` property is causing the flex container to overflow due to the size of its fixed width children

Here's a unique CSS puzzle for you all: Imagine the following hierarchy: app container flex container item1 - fixed width(80px) item2 - responsive width(width:100%). MUI Stepper - overflow:scroll, width:100% This structure would look like this: ...

Basic AJAX request not functioning properly

I am encountering an issue with a very simple AJAX call on my localhost. I am using a Windows 10 Machine with XAMPP running. I have checked the packages, and it seems that the AJAX request is not being sent to handle.php. Can someone help me figure out wha ...

Update the choices in a dropdown menu dynamically using MVC Razor

In my HomeController, I have written a code snippet that is intended to retrieve the latest 6 rows from a database. private List<SelectListItem> GetOriginalIDs(string thisPWS) { List<SelectListItem> list = new List<SelectListItem>(); ...

Error encountered: "Instance variable for Apex chart not defined while attempting to update charts with updateOptions."

I have integrated Apexcharts to create charts within my application. The initial data loads perfectly upon onload, but when applying a filter, I face an issue where the charts need to be refreshed or updated with the new filtered data. I attempted to use t ...

Executing PHP function through AJAX

I have thoroughly researched various resources regarding my issue but still have not been able to find a solution. My goal is to retrieve the result of a PHP function using jQuery AJAX. function fetch_select(){ val_name = $('#name').val(); ...

Await the reply from Angular while using Selenium WebDriver

I am currently automating an Angular-based application using Selenium WebDriver (Java). After selecting an option from a dropdown in the Application Under Test (AUT), data is loaded onto the page through an AJAX call to a web service. However, there is no ...

Tips for displaying a loading indicator above a form

I've been struggling to figure out how to display a loading indicator on top of my form without messing up the styling... https://i.sstatic.net/FFCRW.png My goal is to show the loading indicator when any action, like deleting an item or changing qua ...

Extract information from a specific div element and save it to a text file

I'm currently working on extracting data from a div and sending it to a PHP file using the following JavaScript: $(document).ready(function(){ $('#save').on('submit',function(e) { var bufferId = document.getElementById ...

How to set a cookie within an iframe while using Safari browser

Despite searching extensively on Stackoverflow and various other sources, I have not been able to find a solution that works for my specific case. The scenario is as follows: we have an application on domain A that we do not have control over, and an appl ...

Troubleshooting: Custom JQuery function not functioning as expected

I am currently facing an issue with the jQuery in my website while trying to implement a portfolio element. It seems to be related to the changePortfolio() function, but I am unsure of how to resolve it. $('.projects a[href^="#"]').on('clic ...

Utilize Bootstrap to position the button right next to the input field

I am having trouble aligning the button on the right next to the email textbox. Unfortunately, my attempts have not been successful. Fiddler: https://jsfiddle.net/Vimalan/mt30tfpv/4/ <div class="col-xs-3"> <div class="fo ...