Page 1 of 1
List Conditional Style
Posted: Sun Mar 24, 2013 7:57 pm
by Joe Bohen
Hi,
I am able to iterate over a list and add a class to each Item using:
$('ul li').each(function(index){
Code: Select all
$(this)
.addClass('selected-list');
});
But what I want to do is selectively add the class when a value in a hidden label in the list matches a given criteria. Something like the poor example below. Can I do this?
$('ul li').each(function(index){
if(my label).text = my criteria) {
$(this)
.addClass('selected-list');
}
});
Regards,
Joe
List Conditional Style
Posted: Sun Mar 24, 2013 10:19 pm
by maxkatz
Yes, that's the right approach.
List Conditional Style
Posted: Sun Mar 24, 2013 11:01 pm
by Joe Bohen
Hi Max, can you give me a pointer towards the correct syntax to obtain the value from the label. How do I point to the correct label if I use:
$('ul li').each(function(index){
var read = $('readlbl').text();
console.log(read);
$(this)
.addClass('selected-list');
});
I don't get a value back.
List Conditional Style
Posted: Mon Mar 25, 2013 6:43 am
by Maryna Brodina
Hello!
codevar read = Tiggzi("readlbl").text();/code
This should also help http://docs.tiggzi.com/javascript-api/
List Conditional Style
Posted: Mon Mar 25, 2013 8:46 am
by Joe Bohen
Hi Marina, Sorry I had tried that approach without success I get 'Label' returned and not the value held in the label.
List Conditional Style
Posted: Mon Mar 25, 2013 10:55 am
by Maryna Brodina
Looks like you map to Label in Listitem. You would need to check all results - use next code:
code$('ul li').each(function(index){
var read = $("[name=readlbl]", this).eq(0).text();
........
});/code
List Conditional Style
Posted: Mon Mar 25, 2013 12:07 pm
by Joe Bohen
Thanks Marina, That is exactly what I was looking for I suspected that you might have to qualify the reference to the current label but my javascript knowledge is not yet strong enough.
List Conditional Style
Posted: Mon Mar 25, 2013 1:17 pm
by Maryna Brodina
There is no need to qualify anything. There is a search by name (name=readlbl) inside li and the result is the first found (eq(0))