user3760741
user3760741

Reputation: 163

HTML DOM Tree traversal using jQuery Mobile

I have an HTML DOM Structure like this. I would like to access the text inside "ctitle", "daytime" and "vv". I am at the <button> position. As in $(this) = button:

NOTE: The DOM elements inside <ul>....</ul> are repeated

<ul id="classes">
  <li class="ctitle" />
  <li class="cschedule">
    <table>
     <tr/>
     <tr>
      <td class="vv" />
     </tr>
     <tr>
      <td class="daytime">
     <tr>
    </table>
  </li>
  <li>
    <button />
  </li>
</ul>

Here is my effort but none of them are working.

ctitle= $(this).closest("#classes").find(".ctitle").text();
vv = $(this).closest("#classes").find("table .vv").text();
daytime = $(this).closest("#classes").find("table .daytime").text()

Upvotes: 0

Views: 67

Answers (1)

Jaime Gomez
Jaime Gomez

Reputation: 7067

Based on your example html, and assuming there's some structure in how it's generated and so the order is always the same:

var cschedule = $(this).parent().prev()
var vv = cschedule.find('.vv')
var daytime = cschedule.find('.daytime')
var ctitle = cschedule.prev()

Upvotes: 1

Related Questions