glenn nall glenn nall - 1 year ago 74
jQuery Question

modify javascript to find first letter in a value

I know little about javascript. From what i can see, this shows a set of rows that contain a value (in this case, the author of a WP plugin).

What I'd like to do, instead of finding the data-name value in the row, is find if the first letter of this value is "A". And hopefully i should be able to work on the preceding code to get to this part... :)

thanks so much.

var authors = [];
var author = $(this).attr('data-author');
if ( -1 == $.inArray( author, authors ) )

$.each(authors, function(i, author){
$select.append( $('<option>').html(author) );

var value = $(this).val();

if ( '__pba_none' == value ) {
$('#the-list tr').show();

$('#the-list tr').each(function(){
var $row = $(this);

if ( $row.find('.pba-id[data-author="' + value + '"]').length )

Answer Source

Use Attribute Starts With Selector [name^=”value”] selector.

Selects elements that have the specified attribute with a value beginning exactly with a given string.

$('#the-list tr').each(function() {
  var value = "A";
  var $row = $(this);
  if ($row.find('.pba-id[data-name^="' + value + '"]').length) {
  } else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download