Question

I have a series of div's with assigned class 'steps', each div is separated by a <hr /> element. Each div contains distinct text.

I need to traverse, using prototype, to a specific hr which has a div with certain text.

For e.g. I need reference to <hr /> that is above div containing jkl

<div class="content">abc</div>
<hr />
<div class="content">def</div>
<hr />
<div class="content">ghi</div>
<hr />
<div class="content">jkl</div>
<hr />
<div class="content">mno</div>
<hr />
<div class="content">pqr</div>

I reckon, we need to first find reference to the div, this can be achieved using the following selector:

$$('div.content:contains("jkl")')

But the :contains selector is only supported in v1.7, and I have v1.6 at disposal, that doesn't identify the selector.

Looking forward to a push.

Was it helpful?

Solution

If you don't have 1.7 available you can try this - I don't like doing this but it will work.

$$('div.content').each(function(div){
    if(div.innerHTML.include('jkl'))
    {
       //Do something here
    }
});

here is a jsfiddle of the HTML with this snippet of code http://jsfiddle.net/jwestbrook/zdvyD/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top