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

Troubleshooting Vue v-for loop triggering click events on multiple items simultaneously

After conducting a thorough search, I haven't found a suitable answer for my issue. The problem I am facing involves a v-for loop with buttons on each item, using VueClipboard2 to copy text. Whenever a button is clicked, some CSS changes are applied t ...

The setStyle() method in JavaFX is like CSS Selectors

Is it possible to bind CSS files to style JavaFX components and also change properties dynamically in code? I'm struggling with the setStyle() method as there's limited documentation available on how to use it effectively. Instead of modifying t ...

Filling a select element in an HTML file using AJAX

I've hit a roadblock, trying to display this PHP list. <?php include 'connection.php'; $query = mysqli_query($conn, "SELECT * FROM expense_object ORDER BY code" ); ?> <!DOCTYPE html> <html lang=" ...

Resolve CORS error when uploading images with AJAX and Node.js using FormData

I am incorporating vanilla javascript (AJAX) to submit a form and utilizing Formdata(). The submission of the form is intercepted by nodejs and linked to a database. However, there is an issue that arises when I try to connect with nodejs after adding a f ...

Changing the size of a div using jQuery

I'm attempting to adjust the size of a div element. You can view my progress in this code fiddle: https://jsfiddle.net/bj3m24ks/31/ Kindly refrain from sharing links to other tutorials as I have already explored them all. I attempted to utilize the $ ...

Tips for correctly deleting a duplicate ref Object ID following the removal of a Document

Coming from a background in relational databases, I'm encountering a challenge with a pattern in Mongoose. Let's say we have SchemaA and SchemaB (for example, pets and people): const Person = new Schema({ name: String, pets: [{ ref: ...

Is there a way to create a table with "cells that can be controlled individually" similar to the image provided using HTML and CSS?

I have been searching online for solutions on how to create a table similar to the one in this image, but so far I haven't had much luck. I attempted to use colspan, however, it didn't yield the results I was hoping for. Does anyone have any alt ...

having difficulty altering a string in EJS

After passing a JSON string to my EJS page, I noticed that it displays the string with inverted commas. To resolve this issue, I am looking for a way to eliminate the inverted comma's and convert the string to UPPERCASE. Does anyone know how to achiev ...

Using JQUERY to handle event bubbling in the DOM after an AJAX call

I have been attempting to dynamically append content to a specific div using .ajax() and then utilize the new content within a jQuery Dialog. I believe that my usage of .on() is correct, but it appears that the DOM is not being properly updated. Here is t ...

Dynamic drop-down navigation with rearranging menu

I am attempting to design a drop-down navigation bar with 2 rows. Initially, only 1 row is visible. Upon clicking the visible row, both rows should appear. Subsequently, when one of the 2 rows is clicked, only that specific row should be displayed. Below a ...

Transform your table into an ASCII-art masterpiece using CSS styling techniques

My vision is to style a table "ASCII art" using CSS, like the example below: +------+---------+----+ | Jill | Smith | 50 | +------+---------+----+ | Eve | Jackson | 94 | +------+---------+----+ | John | Doe | 80 | +------+---------+----+ <ta ...

Improved Approach for Replacing if/else Statements

I'm looking to streamline the controller used in my SQL command for filtering records based on specific criteria. The current approach below is functional, but not without its limitations. One major issue is scalability - adding more criteria in the f ...

The occurrence of TypeError in next.js Dropzone stating that (0 , _mantine_core__WEBPACK_IMPORTED_MODULE_0__.rem) is not a function is indicating

I am encountering an issue while trying to render a dropzone component using Next.js and Mantine. For reference, I am following the documentation at . Here is the import statement: import dropzone I am receiving an error message that says: I have inclu ...

Leverage jQuery deferred objects to handle a dynamic amount of AJAX requests

When faced with multiple ajax requests, how can I execute them using deferreds? This is my approach: //qty_of_gets = 3; function getHTML(productID, qty_of_gets){ var dfd = $.Deferred(), i = 0, c = 0; // hypothetical cod ...

Is this code in line with commonly accepted norms and standards in Javascript and HTML?

Check out this Javascript Quiz script I created: /* Jane Doe. 2022. */ var Questions = [ { Question: "What is 5+2?", Values: ["7", "9", "10", "6"], Answer: 1 }, { Question: "What is the square root of 16?", Values: ["7", "5", "4", "1"], Answer: ...

Submit the form only when the specified conditions are met, otherwise return

Is there a way to submit a form after it has been prevented from submitting? I've searched for solutions on StackOverflow but haven't found one that works for me. Below is the code snippet in question: $(function(){ $("#loginform").submit(f ...

Developing a personalized error message pop-up system in Electron

I am currently in the process of developing an application for file backup, which involves a lot of reading and writing to the filesystem. While most parts of the app are functioning well, I am facing some challenges with error handling. In the image belo ...

Show an HTML image encoded in base64 from its origin

Is there a way to embed a base64 image in HTML without having to paste the entire code directly into the file? I'm looking for a more efficient method. For example: <div> <p>Image sourced from an online repository</p> <img src=" ...

Is it possible for the vertical borders of <span> to overlap?

When nesting multiple spans within each other and giving them borders, their horizontal borders overlap by default while their vertical borders stack. Check out a live example on JsFiddle: https://jsfiddle.net/4un9tnxy/ .html: <span><span>a& ...

Is it possible to align items in flexbox to a specific baseline?

Is it possible to specify a baseline override when utilizing flexbox and trying to use align-items:baseline? I have a flex container that contains various divs such as title, image, body, and description. For these flex items, I want them to be centered ...