var qtr = $('div').text();
var qtr1 = qtr.split(',')
console.log(qtr1.length)
for (var i = 0; i < qtr1.length; i++) {
console.log(qtr1[i]);
}
console.log(qtr1);
if ($.inArray('1st qtr', qtr1)) {
alert('1st');
}
if ($.inArray('2nd qtr', qtr1)) {
alert('2nd');
}
if ($.inArray('3rd qtr', qtr1)) {
alert('3rd');
}
if ($.inArray('4th qtr', qtr1)) {
alert('4th');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>1st qtr,2nd qtr,3rd qtr,4th qtr,</div>
I have a div with text in it i want to check if a specific text is in the div. I tried splitting the div text and getting checking $.inArray
but the first text is not being shown even if it is missing.
Problem:
- Why do i get 5 as length in even if there are only 4 text. An extra space is being added at the last
- Why is the first text which is
1st qtr
not shown even if it is existing. - What is the best to
check if a text is existing in a text
.