Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

jQuery .length property

0 votes
3 views
added Apr 2 in jQuery by LC Marshal Second Warrant Officer (6,690 points)
edited Apr 11 by LC Marshal

To check whether elemet exist by .length

$('body').each(function() {
  var expiredprop = $('span.expiry_msg').text();
  if (expiredprop.length > 1) {
    $('#contact-agent-topbar').hide();
  } 
});

3 examples

0 votes
responded Apr 2 by LC Marshal Second Warrant Officer (6,690 points)
edited Apr 11 by LC Marshal

.length() property type

$('span.expiry_msg').length; 

if (expiredprop.length > 1) {
  $('#element').hide();
}  

if ($(expiry).length) { 
  // do this
}
0 votes
responded Apr 5 by LC Marshal Second Warrant Officer (6,690 points)

if the expiry message is exist on the body, do this.

$(function() {
  var expiry = $('span.expiry_msg');  
  if ($(expiry).length) { 
   $(expiry).clone().appendTo('#footer > span.expiry-msg').addClass('footer-expiry').fadeIn(500);
  }
});
0 votes
responded Apr 11 by LC Marshal Second Warrant Officer (6,690 points)

If element height is lesser than 1800, .hide() read-more, else .show()

$('body.page-property-detail').each(function() {
  var propDetailContent = $('.page-property-detail .listing-expandable').text();
  var pdtrimcontent = $.trim(propDetailContent);
  if(pdtrimcontent.length < 1800) {
    // alert('hey!');
    $('.readmore.font-sans').hide();
  }
  else {
    $('.readmore.font-sans').show();
  }
});
lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...