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

jQuery - manipulate non-existed and existed element with operator

0 votes
19 views
added Feb 24 in jQuery by lcjr Second Warrant Officer (4,220 points)
$(window).load(function() { 
  newsui.newsContentBeautify();
  var newsMeta = $('body.page-content .entry-meta'),
      pgNews = 'body.page-content',
      newsMeta = $(pgNews + ' .entry-meta'),
      newsAuthor = $(pgNews + ' .entry-meta .em-author'),
      bodyContent = $(pgNews), 
      topImg = $(pgNews + ' .news-body.content figure.caption.first'), 
      topImg2 = $(pgNews + ' .news-body.content figure.first'),
      topImg3 = $(pgNews + ' .news-body.content p figure.caption.first'),
      firstP = $('body.page-content .news-body.content p:first'),
      secondP = $('body.page-content .news-body.content p:nth-child(2)'),
      firstPiFrame = $('body.page-content .news-body.content p:first iframe'),
      topImg4 = $(firstP).find('figure'),
      newsCarousel = $(pgNews + ' .news-owl'),
      newsDate = $(pgNews + ' .em-date' );
      carouselElem = $(pgNews + ' .news-body.content .news-owl.owl-carousel');

  if(newsCarousel.length) {
    newsMeta.css('margin-top', '30px'); 
    carouselElem.append(newsMeta);
    newsMeta.show();
    console.log('meta with gallery');
  }
  // else if(topImg.length) {
  else if((topImg.length) && (!firstPiFrame.length)) {
    // else if(topImg.length) {
    newsMeta.css({'margin-top': '30px', 'text-align': 'left'}); 
    newsDate.css({'border-bottom' :'6px solid #fff'});
    
    topImg.append(newsMeta);
    newsMeta.show();
    console.log('meta topImg');
  }
  // else if(topImg2.length) {
  else if((topImg2.length) && (!firstPiFrame.length)) {
    // newsMeta.css('margin-top', '30px'); 
    firstP.prepend(newsMeta);
    newsMeta.css({'padding-left': '0'});
    newsMeta.show();
    console.log('meta topImg2');
  }

  else if ($(firstPiFrame).length > 0) { 
    // newsMeta.css('margin-top', '30px'); 
    newsMeta.css({"margin-top": "30px", "padding-left": "0", "margin-bottom": "-25px"});
    firstP.append(newsMeta);
    // newsMeta.css({'padding-left': '0'});
    newsMeta.show();
    console.log('meta video iframe');
  }

  else if($(newsAuthor).text() == '') {
    newsMeta.css({'border-top': '1px solid #fff'});
    newsMeta.css({'padding-left': '0'}); 
    firstP.prepend(newsMeta);
    newsMeta.show();
  }
  
  else {
    firstP.prepend(newsMeta);
    newsMeta.css({'padding-left': '0'})
    newsMeta.show();
    console.log('meta no top img');
  }
    
});

 

Please log in or register to response this reference.

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