Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9164947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:48:10+00:00 2026-06-17T14:48:10+00:00

I have elements (images in <a> tags) list which arranged by dynamic ID. It

  • 0

I have elements (images in <a> tags) list which arranged by dynamic ID. It is possible to select only one of those. Assume that I select any element. This time, I change its style and set “SelectedItem” value to its name attribute to find the selected item in future.
I want that, when mouse over selected item, to change its src value, but jquery function does not work, because I set name=”SelectedItem” attribute with javascript, in runtime, it works after reload a page. When I set name=”SelectedItem” in the code (default, before runtime) it work. But I want to do it without reloading a page.

enter image description here

Shortly, when I do select operation I set name=”SelectedItem” to selected image:

function SelectItem(id) {
var imgId = 'productImage_' + id;
var imgId_element = document.getElementById(imgId.toString());

//my some operations

imgId_element.name = "SelectedItem";
}

And take name’s value when UnSelect.

function UnSelectItem(id) {
var imgId = 'productImage_' + id;
var imgId_element = document.getElementById(imgId.toString());

//my some operations

imgId_element.name = "";
}

I want to set unselect image to background of only selected images. When I Select/Unselect any item with SelectItem()/UnSelectItem() following mouseover()/mouseout() not work.

$("img[name='SelectedItem']").mouseover(function () {
            $(this).attr("src", "/Content/images/select.png");
        }).mouseout(function () {
            $(this).attr("src", "/Content/images/unselect.png");
});

HTML is:

<img src="@Url.Content("~/Content/images/select.png")" id='productImage_@(Model.Id)'  data-id='@Model.Id'  @{if (Model.IsSelected) { <text>name="SelectedItem"</text>} }  alt="" />

How can I solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:48:12+00:00Added an answer on June 17, 2026 at 2:48 pm

    Try:

    $('body').on('mouseover', 'img[name=SelectedItem]', function() {
      this.src = "/Content/images/select.png";
    }).on('mouseout', 'img[name=SelectedItem]', function() {
      this.src = "/Content/images/unselect.png";
    });
    

    By using the 3-argument variant of .on(), you set up a delegated handler on the <body> element. When the mouse events bubble up to that, the handler will check the target element against the selector.

    Now, that said, using the “name” property/attribute for <img> elements doesn’t make a lot of sense; that’s not a valid attribute. You’d be better off adding/removing a class value:

    function SelectItem(id) {
      $('#productImage' + id).addClass('SelectedItem');
    }
    

    and then:

    $('body').on('mouseover', '.SelectedItem', function() { ... })
    

    etc. Finally, you’d be better off using the synthetic “mouseenter” and “mouseleave” events, as those get over some browser oddities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that loads a bunch of images into hidden img elements and
I have been asked to produce a select list that looks like this: The
I have a client that wants to insert videos, images, form elements, etc. into
I have a string that contains HTML image elements that is stored in a
I have one web page where i need to hide some images , some
I have an html that look like this: <ul> <li> <img src=<?php echo base_url();?>assets/images/blue_background.png
I have a webpage in which I am using 2 jsp:include directives. Basically one
I have a text file which is formatted with titles, location of images, and
I have an XML file that uses image tags like this: <Entry> <?image_0 href=http://url.com?>
I have a page that loads with content. I .clone() certain elements, then hide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.