更改动态添加元素的背景

塞雷尼

我想更改dom中最后添加的元素的背景。为了给您更好的外观,这里是html:

    <div class="check-in-wrapper">
       <div class="ui-grid-a">
         <div class="ui-block-a">
            <span class="ticket-img">
                <img class="image" src="img/icons/ticket.png">
            </span>
        </div>

        <div class="ui-block-b">
          <h4>Inchecken</h4>
          <div class="check-in-notification-append"></div>
        </div>
       </div>
     </div>

     <div class="douane-wrapper">
      <div class="ui-grid-a">
       <div class="ui-block-a">
         <span class="douane-img">
             <img class="douane-img image" src="img/icons/douane.png">
          </span>
         </div>

          <div class="ui-block-b">
            <h4>Douane</h4>
            <div class="douane-notification-append"></div>
         </div>
       </div>
     </div>

  <div class="gate-wrapper">
    <div class="ui-grid-a">
     <div class="ui-block-a">
      <span class="gate-img">
       <img class="gate-img image" src="img/icons/gate.png">
      </span>
     </div>

     <div class="ui-block-b">
     <h4>Gate</h4>
       <div class="gate-notification-append"></div>
       </div>
  </div>

当我追加要素check-in-notification-appenddouane-in-notification-appendgate-in-notification-append这里更好的看看js文件。

  $(document).on("pagebeforeshow","#progress",function(){

    var incheckHtml = '';
    var douaneHtml = '';
    var gateHtml = '';

    for(var count = 0; count < info.data.length; count++){
        var shortmessage = info.data[count][3];
        var category = info.data[count][4];
        var typeOf = info.data[count][5];

        if(typeOf === "warning"){
            imgPath = 'img/icons/alarm.png';
        } else {
            imgPath = 'img/icons/alert.png';
        }


        if (!Array.prototype.last){
            Array.prototype.last = function(){
                return this[this.length - 1];
            };
        };


        if (category === 'inchecken'){
            incheckHtml = incheckHtml + "<div class='notification-item'><img class='notification-image' src=" + imgPath + "><span class='notification-text'>" + shortmessage + "</span></div>";
            // $('.check-in-wrapper').empty().prepend(incheckHtml); 
            $('.check-in-notification-append').empty().prepend(incheckHtml);
        }

        if(category === 'douane'){
            douaneHtml = douaneHtml + "<div class='notification-item overlay'><img class='notification-image' src=" + imgPath + "><span class='notification-text'>" + shortmessage + "</span></div>";
            $('.douane-notification-append').empty().prepend(douaneHtml); 
        }

        if(category === 'gate'){
            gateHtml = gateHtml + "<div class='notification-item overlay'><img class='notification-image' src=" + imgPath + "><span class='notification-text'>" + shortmessage + "</span></div>";
            $('.gate-notification-append').empty().prepend(gateHtml); 
        }
    }
});

但是我如何访问删除类别的任何类别中最后添加的元素"overlay"我希望有人能帮助我访问最后添加的元素和removeClass覆盖。我写了一个,.last() function但这只会给我数组中最后一个对象的输出...

JB库珀

我认为您可以通过使用一些适用于所有可能受影响的元素的通用选择器并使用Jquery的last()函数来实现此目的。

$(".allMyThings").last().removeClass("overlay");

https://api.jquery.com/last/

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章