简体   繁体   English

如何 append<li> 内部顶部的标签<ul>在 laravel 中的 jquery 的帮助下?</ul></li>

[英]How to append <li> tag at the top inside <ul> with help of jquery in laravel?

I am developing notification dropdown for my website.我正在为我的网站开发通知下拉列表。 for that i am trying to append <li> tag at the top of drop down.为此,我正在尝试在下拉列表顶部添加 append <li>标签。 but currently it is appending at bottom of <ul> .但目前它附加在<ul>的底部。

i tried to add new ul tag but i think that is not good practice.我尝试添加新的ul标签,但我认为这不是一个好习惯。

html html

<ul class="dropdown notifications no-hover closed notilist">
 @foreach(Auth::user()->notifications->take(4) as $notification)
    @if(!empty($notification['data']['sender_name']))
<li class='dropdown-item'><b>{{$notification['data']['sender_name']}}</b> Bid on your Auction <b>{{$notification['data']['product_title']}}</b> of <b>{{$notification['data']['bid']}}$</b>
</li>
   @endif
  @endforeach
</ul>

jquery jquery

Echo.private('App.User.'+userId)
 .notification((notification) => {
$('.notilist').append("<li class='dropdown-item'><b> "+notification.sender_name+"</b> Bid on your Auction  <b>"+notification.product_title+"</b>  of <b>"+notification.bid+"</b>$</li>")

 });

I want to append that new <li> tag at the top.我想 append 顶部的新<li>标签。

I guess you can look at the jQuery method prepend .我想你可以看看 jQuery 方法prepend Here's the link Prepend这是链接前置

$('.notilist').prepend("<li class='dropdown-item'>text should be here</li>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM