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');         }     }) }); 

jsfiddle example


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -