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 8517961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:51:08+00:00 2026-06-11T05:51:08+00:00

So i was trying to append some code to all my images(for a rollover)

  • 0

So i was trying to append some code to all my images(for a rollover) in a certain portion of my document via javascript (primarily for graceful degredation purposes)etc and so

after noticing my function not work…i wrote a super small function to test it and no good. In this example, what im trying to do is alert an images alt tag but not a specific button div. Essentially, apply said function to all images in a parent div (portSecW) and not the close buttons image/div.

so for the sake of this example, heres some HTML(pseudo):

<div id="portSecW">
  <img src="X" alt="something here"></img>
  <img src="a" alt="something here"></img>
  <img src="b" alt="something here"></img>
  <div class="closeXbtn"><img src="g" alt="something here"></img></div>
</div>

Here is what ive tried.

$('#portSecW img:not(".closeXbtn")').click(function(){
    alert($(this).attr("alt")); 
    return false;
});

Ive also gone about it like this

$('#portSecW img').not('.closeXbtn').click(function(){
    alert($(this).attr("alt")); 
    return false;
});

ive also tried like this but doesnt work (so im assuming that although i get no errors, its not constructed properly because the alert function doesnt fire.)

$('#portSecW img.not(".closeXbtn")').click(function(){
    alert($(this).attr("alt")); 
    return false;
});

So not sure what im doing wrong.

Thanks in advanced.

NOTE: Just incase anyone is looking, the marked “”accepted answer” worked for me but upon further digging. all of my tries above worked, the problem was i wasnt precise enough with how i traversed the DOM. So all of these do the same thing and work. here are the changes i made and again, these all worked.

$('#portSecW a').children('img').click(function(){
    alert($(this).attr("alt")); 
    return false;
});

$('#portSecW img').not(".closeXbtn img").click(function(){
    alert($(this).attr("alt")); 
    return false;
});

$('#portSecW img:not(".closeXbtn img")').click(function(){
    alert($(this).attr("alt")); 
    return false;
});

Thanks Everyone for your help

  • 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-11T05:51:10+00:00Added an answer on June 11, 2026 at 5:51 am

    Use .children():

    $('#portSecW').children('img').click(function(){
        alert($(this).attr("alt")); 
        return false;
    });
    

    The .children() method allows us to search through the children of these elements in the DOM tree and construct a new jQuery object from the matching elements.

    The .children() method differs from .find() in that .children() only travels a single level down the DOM tree.

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

Sidebar

Related Questions

I am trying append some XML retrieved via a dojo.XHRGet to a dijit.layout.ContentPane .
I'm trying to write some code that will print out the dimensions of all
I am trying to append some text to excel cell. For example if the
I'm trying to append some text to a variable in a Makefile for HP-UX's
I am trying to dynamically append some objects to a div and then programatically
I am trying to understand some example code on this web page: ( http://www.csharp-station.com/HowTo/HttpWebFetch.aspx
I'm testing some code(trying to make it faster but also trying to understand the
I'm trying to do a todo-list with html5 localstorage and some JavaScript/jQuery. I use
Im trying to implement some code i found on a website which duplicates a
I am trying to compile some code on linux that I KNOW compiles on

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.