I have the below code which works fine.
<div id="testdiv"></div>
<table>
<tr>
<td class="test" title="two">2</td>
<td class="test" title="one">1</td>
<td class="test" title="three">3</td>
</tr>
</table>
<script>
if(jQuery("td[title='three']").length == 0) {
jQuery('#testdiv').append('<p>no td</p>')
}
else
{
jQuery('#testdiv').append('<p>yes td</p>')
}
</script>
However I want to say if either title one or three are present. So I tried editing the first line of my script to look like this.
if(jQuery("td[title='three']").length == 0 || jQuery("td[title='one']").length == 0) {
But for some reason it seems as though both three and one need to be there for my statement to be true?
But if I replace the || with the && it works how I want it to? Why is it that the && is working like an || here or am I missing something here?
See fiddle for example
||is OR,&&is AND so if you need both conditions to be met you have to use&&, but you can make this a bit shorter. I’m using$for convenience but you can replace withjQuery: