Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Prevent link icon from adding to images

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #28634
    dcp3450
    Participant

    I could have sworn there was an article on css-tricks but I couldn’t find it.

    I have some jquery that adds an icon to links based on file type and external. PDF links get a pdf icon, external links get a external link icon, doc links get a doc icon, etc. However, images are too. I want this to only effect text links. Example of how I add the icons:

    $(‘a[href$=".pdf"]’).append(‘<div class="pdf"></div>’).attr(‘target’,’_blank’).attr(‘title’,’Adobe PDF’);

    How can I tell it to ignore images?

    #73507
    dcp3450
    Participant

    got it! added .not(‘:img’) before the append.

    #73508
    dcp3450
    Participant

    nevermind, didn’t work.

    #61575
    noahgelman
    Participant

    .not(‘:img’) isn’t working because you aren’t applying it to the img, but the a tag around that image. Try using .not(‘:a img’). That way it’s excluding links with images in them.

    #73550
    dcp3450
    Participant

    I tried that and it didn’t work either.

    #73551
    dcp3450
    Participant

    solution:

    .not(‘a:has(img)’)

    #73565
    noahgelman
    Participant

    Yeah, that sounds right. Looking at it now .not(‘:a img’) shouldn’t work. That targets the img inside the link and not the link itself which is what you were trying to do. Good lesson for me.

    #73566
    dcp3450
    Participant

    you and me both! :D

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.