javascript - Check if element value starts with 'http', if true change class of element -
i want check series of elements same class see if value starts 'http' if true elements should have new class added.
$('#btn').click(function () { if ($('span.value').text().indexof('http') == 0 ) { $('span.value').addclass('url'); } else { $('span.value').addclass('noturl'); } });
this jsfiddle i've got far, it's adding new class elements ones don't start 'http'.
i'm not sure problem is?
you need iterate on each span individually:
$('#btn').click(function () { $('span.value').each(function () { if ($(this).text().indexof('http') == 0) { $(this).addclass('url'); } else { $(this).addclass('noturl'); } }) });
Comments
Post a Comment