jquery - How to select the text from the first <a> tag from each <td> element -
i have table of events, , need event name each.
var event_names = new array(); // initialise avoid errors $('td.event_name a', '#the-list').each(function(){ console.log($(this).text()); event_names.push($(this).text()); });
however, fails because there more 1 <a>
tag within td.event_name
, , need first.
i've tried also, i'm getting error $(this).$... not function
.
var event_names = new array(); // initialise avoid errors $('td.event_name', '#the-list').each(function(){ console.log($(this).$('a:first').text()); event_names.push($(this).$('a:first').text()); });
does know how round this?
here source, 1 of <td>
elements. cannot see obvioius selectors work off of in code (and cannot change it).
<td class="event_name column-event_name"> <label><strong><a title="edit event" href="admin.php?page=dd-options-edit-event&event=126" class="edit"> test event </a></strong></label> <img style="display: none; margin-left: 10px;" src="http://test.dynedrewett.com/wp-admin/images/wpspin_light.gif" alt="" class="waiting"> <div class="row-actions"> <span class="edit"><a title="edit event" href="admin.php?page=dd-options-edit-event&event=126" class="edit">edit</a> | </span> <span class="inline hide-if-no-js"><a title="quick edit event" href="#" class="editinline">quick edit</a> | </span> <span class="copy"><a title="copy event" href="#" class="single-copy">copy</a> | </span> <span class="delete"><a title="delete event" href="#" class="single-delete">delete</a> | </span> <span class="open"><a target="_blank" title="close event" href="#" class="single-switch-state">close</a> | </span> <span class="view"><a target="_blank" title="view event" href="http://test.dynedrewett.com/events/?e=126" class="single-view">view</a> | </span> <span class="invitations"><a title="manage invitations event" href="http://test.dynedrewett.com/wp-admin/admin.php?page=dd-options-event-invitations&event=126" class="single-view">invitations</a></span> </div> </td>
use :first
selector, this:
$('td.event_name a:first', '#the-list').each(function(){ console.log($(this).text()); event_names.push($(this).text()); });
for reference, second attempt getting $(this).$ not function
due syntax error, should either of these:
console.log($('a:first', this).text()); console.log($(this).find('a:first').text());
Comments
Post a Comment