Utilize jQuery to find elements based on a specific attribute containing a certain value

I need help targeting specific attributes in links to append classes based on the file extension. My page displays various types of files, from images to .ppt files. I am using ASP.NET MVC and jQuery for this project.

<a class="screenshot" title="" fileext=".ppt" rel="http://google.com/test.jpg" href="#">

Answer №1

$('a[fileext=".ppt"]').addClass('foo');

Looking for ways to apply specific classes to links with different file extensions? Check out these resources:

If you have numerous file types to handle, consider automating the process by matching the value of the fileext attribute to a corresponding class name. Feel free to provide more examples of your links and desired classes for tailored assistance.

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

Footer positioned centrally on screen

My webpage footer seems to be misplaced, appearing in the middle of my content instead of at the bottom where it should be. Surprisingly, the code for the footer works perfectly on other pages. Any suggestions on why this might be happening? I've sco ...

"Unfortunately, the Datatables Individual Column Search feature is not compatible with the

I am currently using Datatables to showcase a large dataset with over a thousand rows in a table format. To enable users to search for specific information within each column, I have implemented the feature of individual column search. The initial setup of ...

What is the best way to successfully implement multiple post requests using Django and Ajax on a single webpage?

After spending the entire day struggling with this issue, I am still unable to make any progress. Let me explain my predicament. In my Django form, I have two fields: redirect_from and redirect_to. The form contains two buttons: Validate and Save. Initial ...

What is the process for activating the Bootstrap modal-backdrop?

While I'm in the midst of some ajax operations, I thought it would be nice to display an overlay on my screen. I could create my own overlay div without any trouble, but considering that I am already utilizing Bootstrap, I might as well take advantage ...

Issues arise when trying to integrate Bootstrap modal with bootcards

I am currently implementing a modal with bootstrap: <div class="modal" id="contact-update-view"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-head ...

What could be the reason for the unexpected behavior of position sticky?

I am encountering an issue while trying to figure out why the container__item--special element behaves as a sticky element in this code snippet <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> ...

CSS - spacing anomaly among inline-block items

I am facing a strange issue with the arrangement of elements in my container div. I have set them to display: inline-block, and they are supposed to expand horizontally if the contents exceed the device width. However, there is an unexpected margin between ...

What is the equivalent of $.fn in AngularJS when using angular.element()?

Currently, I am conducting a directive unit test using jasmine. The test is now functional, but I need to find an alternative for $.fn in angularjs since the use of $ is prohibited in my workplace. Code: (function scrollTopEventDirective(application) ...

Learn how to integrate Bootstrap with Vue.js TreeView in this tutorial

If you're looking to create a treeview using Vue.js, the code structure would resemble something like this: HTML: <!-- item template --> <script type="text/x-template" id="item-template"> <li> <div ...

Steps for setting two items as default selected in a multiselect dropdown

My code snippet below is meant to populate a multiselect dropdown with item values 1 and 2 as default selected, however, only item value 2 ends up being selected: $.ajax({ type: "POST", url: Url_function, data: para_datas, ...

Animating elements on a webpage can be achieved by using both

Is there a way to create an animation that moves objects based on button clicks? For example, when the "Monday" button is pressed, the object with the correct color will move down. If any other button like "Tuesday" is clicked, the previous object will mov ...

Waveform rendering in HTML5 using wavesurfer.js struggles to handle large mp3 files

Recently, I was considering incorporating wavesurfer.js into one of my projects so I decided to explore the demo on To test it out, I uploaded a large mp3 file (approximately 2 hours long) onto the designated area in the middle of the page. It appeared to ...

The response from an AJAX request is consistently negative

Currently, I am working on a basic PHP form that involves some AJAX functionality. Despite my efforts to troubleshoot the issue on my own, I have been unable to identify the missing component. The problem persists as all results return false, and no recor ...

Adding a background image to a box in MUI is a simple task that can enhance

I've been attempting to include a background image in the Box component of mui, but I can't seem to get it to work. Here is the code I've been using: const Main = () => { return ( <Box sx={{backgroundImage:'images/cove ...

Immediate family members nearby are not an option. We will have to create the form dynamically

On a previous page, there is a form that allows users to input data and define the number of "Attributes" they want to assign to a device by clicking on a button. Users are prompted to specify a name and type for each attribute. If the user selects "Selec ...

How can I modify the text color of the Navbar-Brand class in Bootstrap NavBar?

I have been experimenting with various options to change the text color of the `navbar` and specifically the `navbar-brand` item. However, my `.navbar-brand {color: purple;}` CSS class doesn't seem to be working. Can someone please assist me in determ ...

Utilizing deferred to ensure that one function completes before triggering a refresh

In my JavaScript code, I have an ajax call that receives a GUID from the server-side code in the response. After getting the GUID successfully, it is used to make a call to an iframe. The ultimate goal is to refresh the page once the iframe has completed i ...

Begin by utilizing the variables published

I have a form on my website that submits data using ajax, allowing for seamless interaction without page refresh. After the form is submitted, I want to dynamically display the user's input by inserting it at the top of the content. However, I am uns ...

Implementing a strategy to prevent the browser's back button from functioning

Is there a way to prevent the user from using the back button in a single page application? I've tried methods like onhashchange and window.history.forward, but they don't seem to be effective (perhaps because the URL doesn't change). ...

What's the best way to modify the style property of a button when it's clicked in

I am working with a react element that I need to hide when a button is clicked. The styles for the element are set in the constructor like this: constructor(props) { super(props); this.state = { display: 'block' }; this. ...