You need to check the number of elements found, as jQuery returns an empty collection in the event of no elements being found (which evaluates to a truthy value in the if statement):
if ( !$(".first.last").length )
I’d suggest testing against 0 explicitly, rather than relying on a falsey value, though:
if ( $(".first.last").length === 0 )
Related Posts:
- jquery variable syntax [duplicate]
- Can you use if/else conditions in CSS?
- jQuery preventDefault() not triggered
- jQuery onclick not firing on dynamically inserted HTML elements?
- slideToggle JQuery right to left
- How to send a PUT/DELETE request in jQuery?
- How do I select text nodes with jQuery?
- Check if checkbox is checked with jQuery
- Jquery change background color
- Download a specific tag with Git
- How does createOrReplaceTempView work in Spark?
- Infinite Scrolling in Asp.Net MVC with jQuery / AJAX Issues
- What are the difference between $(document).bind(‘ready’, function) and $(document).ready(function() {})
- Get selected value in dropdown list using JavaScript
- What is a hash map in programming and where can it be used
- When to use If-else if-else over switch statements and vice versa
- jQuery Toggle Text?
- Dynamically load JS inside JS
- jQuery how to find an element based on a data-attribute value?
- Display XML content in HTML page
- jQuery: outer html()
- How to change the text of a button in jQuery?
- zsh command cannot found pip
- How can I move a tag on a git branch to a different commit?
- How to pass $(this) properly in click jQuery function
- How to remove specific value from array using jQuery
- Undo text entry in Jupyter Notebook under Win7
- Brackets : how to make autocomplete / autoindent works ?
- How to fire an event on class change using jQuery?
- Is there a Variable Explorer for PyCharm
- Ext.getCmp(id) or Ext.ComponentQuery.query(attribute)
- jQuery UI ” $(“#datepicker”).datepicker is not a function”
- how to remove default jquery and add js in footer?
- Enable Submit Comment Without Page Reload (Using Ajax)?
- WordPress 5.5 – ReferenceError: commonL10n is not defined error
- WP available widget for certain area
- Media manager multiple selection
- How to include jQuery properly?
- Plugin admin page meta_box toggle and order state not saving
- Confused about shortcode and settings values
- Running jquery script after shortcode [closed]
- Uncaught TypeError: jQuery is not a function
- WordPress customizer refresh screen after save
- Include jQuery plugin in WordPress
- Slider loading issue
- Best WordPress Slider Plugin for HTML and Images
- Trying to remove duplicate jquery scripts
- Limit Widgets to Sidebar ID’s
- Ajax post filters not working
- jquery.validation.js is not working in woocommerce checkout page form
- How to make an WordPress element sticky? [closed]
- Add / Update Custom Fields After Select Pictures in Media Window
- Can I move a WordPress installation to an IP (without domain name)?
- Using function from enqueued .js file in theme in plugin?
- Moving jQuery to footer from header
- jQuery plugin not loading
- Search query with Ajax
- After inserting jquery weather code, my responsive menu is lost
- Ajax Favorite from foreach (how to specify which result result is processed)
- wp.media gallery collection sometimes undefined
- $ is not defined [duplicate]
- wp_deregister_script(‘jquery’) not working
- How Do I change Markup of a link in WordPress
- Plural Forms error in Query Monitor
- replacing jquery google cdn with a new version dynamically
- JQuery toggle in Visual Composer
- jQuery does not appear to be enqueued on static homepage
- Pass WP post content to a jQuery plugin (Fancybox)
- Drop Down Category Menu Not Working
- controlling the showing and hiding of the website logo
- Not able to remove a class from an element using JQuery [closed]
- Individual Pages are loading halfway down
- jQuery datepicker not showing on admin menu
- How do I deal with a compromised server?
- Something is burning in the server room; how can I quickly identify what it is?
- Finding out what user Apache is running as?
- Do systemd unit files have to be reloaded when modified?
- What is a glue record?
- How do I convert a .cer certificate to .pem?
- Run Oracle SQL script and exit from sqlplus.exe via command prompt
- Show full process name in top
- How do you do load testing and capacity planning for web sites?
- What is a good SSH server to use on Windows? [closed]
- In systemd, what’s the difference between After= and Requires=?
- Windows Server restart / shutdown history
- How do I set the global PATH environment variable on OS X?
- nmap find all alive hostnames and IPs in LAN
- Should CNAME Be Used For Subdomains?
- How do I create user accounts from the Terminal in Mac OS X 10.5?
- How to get a .pem file from ssh key pair?
- How to inspect remote SMTP server’s TLS certificate?
- Choosing between meaningful and meaningless hostnames [closed]
- logrotating files in a directories and its subdirectories
- Multiple TXT fields for same subdomain
- How to restart Nginx on Mac OS X?
- Do SPF Records For Primary Domain apply to subdomains?
- Why is the response on localhost so slow?
- apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
- Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php
- Can’t seem to check off a category checkbox with jquery?