We help IT Professionals succeed at work.

identify all "a" tags with "Edit" in the middle

Tom Knowlton
Tom Knowlton asked
on
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gv1','Edit$18')">Edit</a>


I want to get all of these anchor tags with "Edit" in the middle  (between the <a> and </a>

S('a')

but then I am not sure what.  Is it val(  )  html(  )  or   text(  )?
Comment
Watch Question

Tom KnowltonWeb developer

Author

Commented:
This seemed to work:


 $('a').each(function ()
        {
            var atxt = $(this).text();

            if (atxt == "Delete")
            {
                $(this).css("float", "right");
            }
        });


For points...how could I optimize this?
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
your script look fine : http://jsfiddle.net/dyKeM/

another one : http://jsfiddle.net/dyKeM/2/
be careful, work for Deletexyz
    $('a:contains("Delete")').css("float", "right");

Open in new window


another one : http://jsfiddle.net/dyKeM/4/

    $('a').filter(function() { return $(this).text() == "Delete" }).css("float", "right");

Open in new window



Tom KnowltonWeb developer

Author

Commented:
Thank you.
Tom KnowltonWeb developer

Author

Commented:
NOTE:

What I wanted on the page was instead of

Edit  Delete
Edit  Delete
Edit  Delete

I wanted to create more space between them.  Some users with butter fingers end up deleting when they meant to edit:

Edit                   Delete
Edit                   Delete
Edit                   Delete

The above code does this (thx again)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.