1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Get element by ID on the fly

Discussion in 'jQuery' started by yourwish, Nov 10, 2015.

  1. #1
    I have lots of image on the page.

    <img src="images/qview.gif" id="demo1" width="24" height="24" data-url="demo-modal.html" class="zoom-btn">
    <img src="images/qview.gif" id="demo2" width="24" height="24" data-url="demo-modal.html" class="zoom-btn">... and so on
    I want to get ID of the image on mouseover using jQuery. How to?
     
    yourwish, Nov 10, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    var imgID = $('img:hover').attr('id');

    Should work.
     
    PoPSiCLe, Nov 10, 2015 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,731
    Likes Received:
    1,998
    Best Answers:
    252
    Trophy Points:
    515
    #3
    Side note, 90%+ of the time (pulling a percentage out of my backside) you are using JavaScript to trap a hover, you are likely doing something wrong -- specifically using JavaScript to do CSS' job.

    Hence why I say the majority of what people use jQuery for belongs in the cutting room floor.
     
    deathshadow, Nov 11, 2015 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,479
    Likes Received:
    4,452
    Best Answers:
    123
    Trophy Points:
    665
    #4
    In this instance he's probably stuffing cookies or tracking user movements on the page and css can't do that.
     
    sarahk, Nov 11, 2015 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,731
    Likes Received:
    1,998
    Best Answers:
    252
    Trophy Points:
    515
    #5
    Oh, the type of sleazeball BS that makes people disable scripting and gives cookies a bad name... gotcha.
     
    deathshadow, Nov 11, 2015 IP
    sarahk likes this.