質問

What I am trying to do is to get an element out of a list. I want to take the text in a link and click on the link if it contains the right text. this is the html-code:

<table>
 <td>
    <tr><a href='...'>I need help</a></tr>
    <tr><a href='...'>Oh hello</a></tr>
    <tr><a href='...'>Lorem ipsum</a></tr>
 </td>
</table>

I tried this:

 .click('table > td > tr > a:contains("I need help")')

But for some reason it doesn't work.

I can't use this:

.click('table > td > tr:nth-child(1) > a)

because there will be added more tr tags as the site gets bigger.

Any ideas ?

役に立ちましたか?

解決 2

First of all, your HTML code is a bit twisted; a <td> has to be a child of an <tr> element, not the way around. I suggest to read the MDN Docs regarding <table> elements.

Regarding your problem with Dalek; Dalek uses the CSS selector engine of the browser that it executes. This will change in the future (Replaced by Sizzle as a unified selector engine), but I have no estimation when this future exactly will be.

Regarding the :contains() pseudo selector - As far as I know, this is gone. The current CSS3 spec has removed it & therefor you can't use that in your Dalek selectors.

他のヒント

You did not create table properly, it should be:

<table>
     <tr><td><a href='...'>I need help</a></td></tr>
    <tr><td><a href='...'>Oh hello</a></td></tr>
    <tr><td><a href='...'>Lorem ipsum</a></td></tr>
</table>

and this js code working properly

$(document).ready(function(){
    $("table tr td a:contains('I need help')").click(function(){


    });
  });
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top