locked
jquery problem RRS feed

  • Question

  • User932259438 posted

    Hi,

    I want retrieve from gridview using jquery Basketball:

    <div class="sports">
                                                            <li>
                                                                <a class="category" id="ContentPlaceHolder1_gvMaster_lnkGroupTeam_1" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gvMaster$ctl03$lnkGroupTeam','')"><img id="ContentPlaceHolder1_gvMaster_imgicon_1" style="height:16px;width:16px;" src="images/2.png"><span class="sport" id="ContentPlaceHolder1_gvMaster_lblsportid_1" style="margin-left: 2px; margin-top: -2px">Basketball</span></a>
                                                            </li>
                                                        </div>

    But problem is how can I retrieve if click on Football or other text?

    Tuesday, May 31, 2016 2:29 PM

Answers

  • User281315223 posted

    jQuery supports a contains selector that will allow you to target a specific element based on it's content :

    var basketballElement = $(".sport:contains('Basketball')");

    Likewise, football would be queired in the same manner :

    var footballElement = $(".sport:contains('Football')");
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 31, 2016 3:23 PM
  • User61956409 posted

    Hi progy85,

    Firstly, as Rion said, you could try to use jQuery :contains() selector to find elements that contain the specified text.

    "><span class="sport" id="ContentPlaceHolder1_gvMaster_lblsportid_1" style="margin-left: 2px; margin-top: -2px">Basketball</span>

    Secondly, you could detect if the text of <span> you clicked contains the specified text on click event.

    $(".sport").click(function () {
        var txt = $(this).text();
        if (txt = "Basketball") {
            //your code
        }
    })
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 1, 2016 2:48 AM

All replies

  • User281315223 posted

    jQuery supports a contains selector that will allow you to target a specific element based on it's content :

    var basketballElement = $(".sport:contains('Basketball')");

    Likewise, football would be queired in the same manner :

    var footballElement = $(".sport:contains('Football')");
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 31, 2016 3:23 PM
  • User61956409 posted

    Hi progy85,

    Firstly, as Rion said, you could try to use jQuery :contains() selector to find elements that contain the specified text.

    "><span class="sport" id="ContentPlaceHolder1_gvMaster_lblsportid_1" style="margin-left: 2px; margin-top: -2px">Basketball</span>

    Secondly, you could detect if the text of <span> you clicked contains the specified text on click event.

    $(".sport").click(function () {
        var txt = $(this).text();
        if (txt = "Basketball") {
            //your code
        }
    })
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 1, 2016 2:48 AM