jQuery .length property

0 votes
662 views
added Apr 2, 2018 in jQuery by LC Marshal Captain (25,790 points)
retagged Sep 21, 2018 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();
  } 
});

6 Responses

0 votes
responded Apr 2, 2018 by LC Marshal Captain (25,790 points)
edited Apr 11, 2018 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, 2018 by LC Marshal Captain (25,790 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, 2018 by LC Marshal Captain (25,790 points)
edited Sep 21, 2018 by LC Marshal

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();
  }
});
0 votes
responded Sep 21, 2018 by LC Marshal Captain (25,790 points)
//when text is not exist, do this

$('body.page-my-all-units').each(function() {
  var historyList = $('.row.portfolio-account-history .control-label').text(); 
  if (historyList.length < 1) {
      $('.view-filters').hide();
      $('.view.view-all-transactions-block').html('<span>No activities so far</span>'); 
  } 
});

 

0 votes
responded Apr 15, 2019 by LC Marshal Captain (25,790 points)
if ($('.skin-ads').length) {
  $('.new-theme').css({'top': '300px', 'margin-bottom': '300px', 'transition': 'all .5s .2s ease-in-out'});
} 

 

0 votes
responded Feb 14, 2020 by lcjr First Warrant Officer (11,790 points)
if(newsnoTopImg.length) {
  if(newsCarousel.length) {
    newsMeta.css('margin-top', '30px'); 
    carouselElem.append(newsMeta);
    newsMeta.show();
    console.log('gallery placement');
  } else {
    firstP.prepend(newsMeta);
    newsMeta.css({'padding-left': '0'})
    newsMeta.show();
    console.log('no figure placement')
  
  }
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...