Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to chk if span tag contain text or not

see fiddle if patient has time slot alloted already then make color yellow using jquery(client side). in my fiddle if i allot time slot first time then color is green and at the same time when allot next time slot then previous time slot is grey. i have to make it yellow. for that i have to find span tag in table and check wheather contains text or not if contains text then make it yellow.But i m new in jquery.i search lot but not getting. how can i do that.

//This is button click code

  $("#<%=btnSelect.ClientID%>").click(function ()           {


                var cells = $('#tableAppointment tbody tr td:nth-child(3)');


                var i = 0;
                var topcell = false;

                cells.each(function ()
                {
                    var $cell = $(this);

                    if ($cell.hasClass('csstdhighlight'))
                    {
                        if (i == 0)
                        {
                            $cell.find('span').text(jQuery('#<%=txtPatientName.ClientID%>').val());
                            topcell = $cell;
                        }
                        else
                        {
                            $cell.remove();

                        }
                        i++;
                    }
                });
                if (topcell && i > 1) topcell.attr('rowspan', i);
                $("#tableAppointment tr").each(function ()
                {

                    $('td', this).each(function ()
                    {
                        var value = $(this).find("span").val();

                        if (!value)//i m chking like this
                        {

                        }
                        else
                        { //make it yellow                      
                        }
                    })

                })

                return false;
            });
        });
like image 400
Nikhil D Avatar asked Jun 14 '12 07:06

Nikhil D


2 Answers

if($('span').text().length == 0){
  console.log('No Text');
}
else{
  console.log('Has Text');
}

Demo: http://jsfiddle.net/hj4Bt/1/

like image 199
Dipak Avatar answered Sep 21 '22 15:09

Dipak


Use $(this).find("span").text() instead. Check if the returned string is empty.

like image 44
Kennyan Avatar answered Sep 19 '22 15:09

Kennyan