Forums

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

Home Forums JavaScript jQuery selector for anchors that only contain text

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35227
    tunes3540
    Member

    I need a selector for all anchors that only contain text. I don’t want anchors that have images or any other element between the opening and closing a tag.
    I’ve found selectors for specific text like $(a:contains(‘specific text’);
    I tried $(a:contains(text); but no joy.

    #90919
    tunes3540
    Member

    Here is what I came up with after finding a stackoverflow question for the opposite (find the ones with no text). Here


    jQuery('a').each(function(){
    if (jQuery(this).text().trim().length){
    Do something with (this)
    }
    });

    It works like I hoped.
    Jsfiddle

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