Discovering similar values between two attributes through jQuery

For the scenario outlined here, a variable is being used to load ajax content.

var postname = itsname;

The goal is to retrieve the value of data-slider by matching it with the data-postname attribute using jQuery. In this case, the desired result is 2 in order to load the correct slide.

<div id="mydiv">
    <a data-slider="0" data-postname="somename" href="#"></a>
    <a data-slider="1" data-postname="anothername" href="#"></a>
    <a data-slider="2" data-postname="itsname" href="#"></a>
</div>

Thank you for your assistance and time.

Answer №1

let name = "whatever",
    selection = $("#myelement a[data-name='" + name + "']").data("selection");

console.log(selection);  // "2"

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

Guidelines for redirecting a page after a jQuery ajax call is made?

I'm working on a login form code and facing an issue where, after the statement is true, it doesn't redirect to the home page. Instead, it just displays the home page on my index page. How can I redirect jQuery Ajax to another page after the sta ...

Adding toggle switches dynamically to a JQuery mobile listview is a convenient and efficient way to

I am attempting to dynamically add a new Listview Item with a Toggle switch inside, triggered by a button click. However, I am only able to get a Checkbox inside the item. Can someone please guide me on what steps I should take? Here is my code: <!DOC ...

Utilizing $.getJSON to initiate a selection change event

I'm currently working on implementing a feature that involves adding categories to a dropdown list using jQuery Ajax. The goal is to load subcategories when a particular option is selected. However, I've encountered an issue where the addition o ...

Employing the html.validationmessagefor to display a client-side error notification

My text fields have server-side validation messages. The field 'title' is a required field on the server side with a '[Required]' data attribute in the class, but it only seems to be checked on a postback or form submit. I am saving the ...

Following the modification of the Context root, the JSP page is no longer functioning as expected

Recently, I developed a JSP page within the webapp that utilizes jquery, CSS, and Angular JS. The files jquery-1.12.0.js, angular.min.js, and TableCSSCode.css are all located in the same directory as the JSP page. Initially, my application context was set ...

How can I use AJAX to remove a record from a MySQL table?

I am looking to create a button with an image X that, when clicked, will delete a row from the database at that exact moment. teste-checkbox.php <style> table { font-family: verdana; font-size: 12px; } table th { text-align: left; backgrou ...

Is the Bootstrap datetimepicker malfunctioning without any console errors to indicate a potential conflicting script?

http://www.pierceresults.com/pierce-results-seminars/PRS-Level-1-October-2015-Marietta-GA When using OpenCart, I encountered an issue with a time field for registrants to select an appointment time. The time, date, and datetime option types are not functi ...

I am puzzled as to why my jQuery height and width functions are returning NaN as the result

I am attempting to calculate the ratio of height and width for each image on a webpage. Unfortunately, I am consistently receiving a NaN result and I cannot figure out why. I have been using get() and find() <div class='image-wrapper'> ...

Obtaining a date and time in PHP from a JavaScript array

I am currently working on implementing a JQuery datetime picker and my goal is to save the selected date and time into a PHP variable for storage in a MySQL database. Despite browsing through various examples, none of them seem to be effective in achieving ...

The issue with Go Code is that it fails to display the JSON data received from a jQuery

Problem Description The issue I am facing is that Go Code is not displaying the posted JSON value from jQuery AJAX. Main Go Code routing := chi.NewRouter() routing.Post("/authenticate", AuthenticateRouter) Go Code Snippet func AuthenticateRouter(w http. ...

Optimizing the speed and load performance of SQLite in Phonegap

As someone who is new to Android programming, I am seeking advice on how to optimize the performance of my phonegap SQLite application. Currently, it takes 30 seconds to load 150 words when I hit the refresh button. Can anyone provide tips on how to enhanc ...

How can I set the input tag to reset back to 1 when a certain event occurs?

I am currently developing an HTML Snakes And Ladders game. On the settings screen, there is an input field where users can select the size of the board. Depending on their choice, they will be able to choose a maximum number of snakes and ladders. For exa ...

Add numerous submit buttons within a form. Upon clicking on a button, the form should be submitted to a specific URL using AJAX

I have a form with two submit buttons: one labeled as "SUBMIT" and the other as "SCHEDULE NEXT ROUND". When a user clicks on the "SUBMIT" button, the form values should be stored in the database and redirect to the view page. If they click on the "SCHEDULE ...

Creating a diagonal effect on a table using jQuery

I am interested in adding a diagonal effect to my table. For instance, if I have a 5x5 table, I want to highlight the first row and set the background color of the corresponding column in that row to red. The same should be done for each subsequent row. ...

Why is it that I am receiving just one object as a string when making an ajax call, even though the controller is supposed to be returning

I'm having trouble understanding why my $.get call is returning one single object with a string containing my elements, instead of the expected list of objects returned by my controller. Controller: public JsonResult GetInitialTags(int id) { Mod ...

Attempting to compare the HTML datetime with the current time in order to implement conditional formatting

I am working with a SharePoint discussion list that includes a field named "Last Updated." My goal is to identify and highlight rows where the last update was more than 1 hour ago. Here is my current approach: <html> <head> <sc ...

Identify and target a particular DIV based on the URL for customization

My webpage has a collection of frequently asked questions (FAQs) on a page called faq.html. Here is an example structure: <div id="faq1">...</div> <div id="faq2">...</div> I am looking to create a pulsating or highlighting effect ...

Using the latest version of Rails (3.1), integrating Paperclip for file uploads, and

I've been trying to configure Ruby on Rails 3.1 with Paperclip and jQuery fileupload. Although I followed a tutorial from the jQuery fileupload page, I am facing issues with getting Paperclip to process the uploaded file. Here is a brief overview of ...

How to Use Radio Buttons in Material-UI to Disable React Components

Just starting out with ReactJS and Material-UI, I've been experimenting with them for about 3 weeks. Currently, I'm facing a challenge where: - There are 2 radio buttons in a group and 2 components (a text field and a select field); - The goal is ...

Leveraging Jquery for Enhanced Bootstrap Functionality in Angular 2

Recently diving into NG2, I've been experimenting with adding Slide Up/Down effects to the default Bootstrap 4 Dropdown component. The Bootstrap dropdown component comes equipped with two jQuery Listeners, $(el).on('show.bs.dropdown') and $ ...