4

User List

This is my user-list.

I need to change the red circular label.

$("#infoListBox .label").text($("#infoListBox a").length); $("#infoListBox .list").bind("DOMSubtreeModified",function(){ $("#infoListBox .label").text($("#infoListBox a").length); }); 

When the document loads, get the number on (red) tag and change the label; next, a tag remove (change label from 21 to 20).

I want to improve this code.

My solution in a better way.

function getUserLength(){ return $("#infoListBox .label").text($("#infoListBox a").length); } // user count getUserLength(); $("#infoListBox .list").bind("DOMSubtreeModified",function(){ $("#infoListBox .label").val(getUserLength()); }); 

I use jade template engine, my jade code below..

div(id='infoListBox').ui.fluid.vertical.menu div.header.item Users a.ui.red.circular.label div.list.item a.item Me a.item 조제우 a.item 장형주 a .item 남중민 a.item Me a.item 조제우 a.item 장형주 a.item 남중민 a.item Me a.item 조제우 
7
  • Can you post the HTML code for the dropdown? Commented Dec 18, 2013 at 13:38
  • Shouldn't you be using MutationObserver? Commented Dec 18, 2013 at 13:39
  • $("#infoListBox .label").html($("#infoListBox a").length) Commented Dec 18, 2013 at 13:40
  • 2
    That's a sexy list ;) Commented Dec 18, 2013 at 13:41
  • @quik_silv Add Jade template codes Commented Dec 18, 2013 at 13:44

2 Answers 2

1

I guess $("#infoListBox .label") is representing a label or span. So use .text()

$("#infoListBox .label").text(getUserLength()); 

Updates: no need of above too, simply

$("#infoListBox .list").bind("DOMSubtreeModified",function(){ getUserLength(); }); 

Since getUserLength() already showing the length in the red circular label, so just call this method in DOMSubtreeModified event.

Sign up to request clarification or add additional context in comments.

3 Comments

I use a tag because of my code based semantic-ui. using .text() , return [Object Object]. thanks @Praveen Jeganathan
@ChangJuPark can you check $("#infoListBox .list").bind("DOMSubtreeModified",function(){ getUserLength(); }); since you already doing it in getUserLength() method.
@ChangJuPark I'm glad I was able to help :)
0

try this

function getUserLength(){ return $("#infoListBox a").length; } getUserLength(); $("#infoListBox .list").bind("DOMSubtreeModified",function(){ $("#infoListBox .label").html(getUserLength()); }); 

1 Comment

thanks @Sidharthan but $("#infoListBox .list").bind("DOMSubtreeModified",function(){ getUserLength(); }); this is more simple

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.