relocate the image with an identical filename stored in the variable

Having trouble moving an image to a new position when clicking on its small thumbnail. I've attempted using jquery's find() function but it doesn't seem to be working...

$('#slide1_controls img').click(function (event){
    var srcs=$(this).attr("src");
    $('#slide-frame').find("img[src=srcs]").animate({
         "left": "+=350px"
     }, {
         "queue": false,
             "duration": 1000
     }).animate({
         'opacity': '1'
     });
});

http://jsfiddle.net/ang3lo0o/Fmsvx/

Answer №1

To incorporate the variable srcs into your .find(), you will have to use string concatenation.

$('#slide-frame').find("img[src='" + srcs + "']").animate({

Answer №2

Adding onto tymeJV's response, consider using a more refined approach with the .on() method.

$('#slide1_controls img').on('click',function (event){
  var srcs=$(this).attr("src");
  $('#slide-frame').find("img[src='"+ srcs +"']").animate({
     "left": "+=350px"
  }, {
     "queue": false,
         "duration": 1000
  }).animate({
     'opacity': '1'
 });
});

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

Utilizing Material UI Grid spacing in ReactJS

I'm encountering an issue with Material UI grid. Whenever I increase the spacing above 0, the Grid does not fit the screen properly and a bottom slider is visible, allowing me to move the page horizontally slightly. Here is the simplified code snippe ...

Struggling to keep checkbox selected while paginating with jQuery

My pagination setup includes 4 buttons (first, move next, move back, and last) along with checkboxes that I want to maintain throughout the pagination process. The issue I'm facing is that when I select a checkbox, move to the next page, and then retu ...

Unable to include an additional parameter within a JavaScript function

I'm having trouble adding a parameter to the Openpopup() function - every time I try, I get an error. Can someone help me out with this? Thanks in advance. return "<a onclick='return Openpopup()' class='btn btn-info btn-lg clickBtn& ...

What are some effective ways to optimize a scrolling script?

Within my div element, I have a list of ordered elements (ol) that I am manipulating with drag and drop functionality using jQuery Nestable. If you could help me troubleshoot this issue, it would be greatly appreciated: How to scroll the window automatical ...

Node.Js Web Scraping: How to Extract Data from JavaScript-Rendered Pages Using Request

I am looking to extract specific content from Google search results that is only visible in browsers, potentially due to Javascript being enabled. Specifically, I am interested in scraping the Knowledge Graph "People also search for" information. Currentl ...

How to add icons to HTML select options using Angular

Looking for a way to enhance my component that displays a list of accounts with not only the account number, but also the currency represented by an icon or image of a country flag. Here is my current component setup: <select name="drpAccounts" class= ...

Creating an XPATH Selector with SCRAPY

Having trouble retrieving the product name from a webpage: Struggling to locate XPATH that delivers a useful, specific result. Apologies for my initial question being quite basic :( class V12Spider(scrapy.Spider): name = 'v12' start_ur ...

What is the reason for AngularJS not invoking the said function?

I need to trigger a function when the app starts in order to display a modal. I have attempted to do this by... The function is invoked using the onDeviceReady event. document.addEventListener("deviceready", onDeviceReady, false); function onDeviceR ...

The JQuery error encountered was due to a missing colon after the property ID

I'm currently working on some jQuery code that is supposed to hide one paragraph and show another when a specific action is triggered. I have created a class called "showp" which displays the targeted paragraph while ensuring that other paragraphs are ...

Can we define a style or CSS for one element depending on the characteristics of another element?

One challenge I'm facing involves a 3rd party library (fullcalendar) that automatically sets the height of elements based on internal calculations to ensure they look good in any viewport: <div style="height: 72px;"> Unfortunately, not all ele ...

Print the page number using HTML and PHP

Is there a way to center page numbers in HTML? I have the code below that echoes the numbers, but they always appear on the left side of the page. I tried wrapping them in a div to center them, which worked, but then each number is enclosed in its own d ...

"Effortlessly move elements with HTML5 drag and drop functionality from either direction

I'm working on an application that requires Html5 Drag and Drop functionality, which is currently functioning well. However, in the app, there may be instances where a dropped item is no longer needed and I want to allow users to re-drag and drop it b ...

To replace basic SVG icons upon clicking with the use of HTML, CSS, and jQuery - here's how!

I have a simple question about inline SVG icons and how to handle them in HTML, CSS, and jQuery. Despite reading numerous resources, I still struggle with implementing the functionality where clicking on one icon changes it to another. My objective: To to ...

The importance of utilizing local variables to securely store values passed from an Ajax call to a WCF method

Currently, I am experimenting with WCF and Jquery ajax for testing purposes. Although I am new to WCF, I encountered a problem with my "ProductsService" service that has four parameters being invoked from Jquery Ajax. Fortunately, I was able to resolve the ...

Please disable zoom functionality on the website specifically for Android devices

Is there a way to disable the zoom feature on our website specifically for Android phones/devices without affecting iPhones? Perhaps targeting the Chrome browser on Android would be sufficient, but we should also verify the mobile screen size. ...

Use jQuery to change the background color when clicked

Below is the HTML code with UL and LI elements: <UL> <LI><span id='select1'>Text</span></LI> <LI><span id='select2'>Text</span></LI> <LI><span id='select3'>Tex ...

Encountering a "GET" error while attempting to make a post request to a WCF Web

I have been working on an MVC project where I am attempting to post data to a WCF Service using a web form and AJAX call. However, I am encountering an error when the request reaches the WebService and it simply says "GET". Here is a screenshot of the iss ...

The nuSelectable plugin enhances the functionality of jQuery

I am currently experimenting with the jQuery nuSelectable plugin in order to enable users to select multiple items simultaneously. Unfortunately, I am encountering difficulties in making the selection work as intended. You can find the plugin here. After ...

Finding matches within a specific group in regular expressions

I am currently tackling the challenge of implementing a feature that involves detecting and linking phrases like "Co. Reg. No" in a specific HTML element. <div class="entry">The company with Co. Reg. No 1241515 will...</div> My goal is to cre ...

The issue with CKEDITOR is that it fails to send data through ajax upon the initial submission

When using CKEDITOR, I am experiencing an issue where my forms do not send data to the server on the first submit. If I click the submit button once, empty fields are sent without any input from me. However, when I submit the form a second time, only then ...