PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

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

 January 30, 2022     css, javascript, jquery, laravel, laravel-5     No comments   

Issue

I am developing notification dropdown for my website. for that i am trying to append <li> tag at the top of drop down. but currently it is appending at bottom of <ul>.

i tried to add new ul tag but i think that is not good practice.

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

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.


Solution

I guess you can look at the jQuery method prepend. Here's the link Prepend

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


Answered By - Liviu Doloscan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing