Reputation: 181
I am trying to get items according the first letter e.g if the items first letter is A I wand that item to appear in divA e.t.c
my code:
function onS() {
var lstString = "";
var Enum = listItems.getEnumerator();
while (Enum.moveNext())
{
var currentItem = Enum.get_current();
lstString += "<br/>" + currentItem.get_item("Title").substring(0,1);//here I check the first letter.
if (lstString = "A") {
$("#divA").html(); //here I want to get that item
}
}
}
Upvotes: 1
Views: 61
Reputation: 12864
If I understand your question, you can do it like this :
if( currentItem.get_item("Title").substring(0,1).toUpperCase() == 'A' )
// or
if( currentItem.get_item("Title")[0].toUpperCase() == 'A' )
Note : You need to use ==
instead =
into an if
condition.
Upvotes: 1
Reputation: 11
var word = 'Aword';
var firstLetter = word[0];
var selector = '#div' + firstLetter;
var container = $(selector);
container.html(word);
Do you mean something like that? Here is the working example: http://jsfiddle.net/9rky2nwh/
Upvotes: 0