JavaScript Shows same length after deleting some items from list with remove()

Suppose I have a list of 3 items in an unordered list as follows

<ul class = "list">
 <li>1</li>
 <li>2</li>
 <li>3</li>
</ul>

Using .remove() I can remove the third as given

var listitems = $('.list li');
listitems.eq(2).remove();

then in dom i can see that the last item is removed. But if I

alert(listitems.length);

It shows that there are 3 items in the list inspite of only two items are showing in the window. Does javascript suppose tho behave like it? If yes please explain.

Answer:1

You are putting the .list li inside a variable at page load and its original value will be allocated to memory unless you update it. You will have to use $('.list li').length or update that variable:

var listitems = $('.list li');
listitems.eq(2).remove();
console.log($('.list li').length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class = "list">
 <li>1</li>
 <li>2</li>
 <li>3</li>
</ul>
Answer:2

In our application we are facing one issue. In my local eclipse whole application is working fine. But in Prod server we are facing this issue-When I want to load one page it is throwing error. The ...

In our application we are facing one issue. In my local eclipse whole application is working fine. But in Prod server we are facing this issue-When I want to load one page it is throwing error. The ...

  1. xmlhttprequest network error 0x2efd
  2. xmlhttprequest network error 0x2eff
  3. xmlhttprequest network error 0x2ef1
  4. xmlhttprequest network error access is denied
  5. xmlhttprequest network error 0x2efe
  6. xmlhttprequest network error 0x2ee2
  7. xmlhttprequest network error 0x800c0019
  8. xmlhttprequest network error 0x2ee7
  9. xmlhttprequest network error 0x2f78
  10. xmlhttprequest network error 00002eff
  11. xmlhttprequest network error 0x2ee4
  12. xmlhttprequest network error 0x2f7d
  13. xmlhttprequest network error 0x2efd ie11

I have a custom directive like this: <user-preview closable="true" user="user" ng-repeat="user in users"></user-preview> As you can see, I pass two attributes to it: closable and user. ...

I have a custom directive like this: <user-preview closable="true" user="user" ng-repeat="user in users"></user-preview> As you can see, I pass two attributes to it: closable and user. ...

  1. passing multiple values in like in sql
  2. passing multiple values to a stored procedure parameter
  3. passing multiple values in json string
  4. passing multiple values in where clause
  5. passing multiple values in query string
  6. passing multiple values in url
  7. passing multiple values in query parameter
  8. passing multiple values to bootstrap modal
  9. passing multiple values in xml
  10. passing multiple values in one parameter in sql
  11. passing multiple values in prepared statement
  12. passing multiple values in in clause in sql query
  13. passing multiple values in query string asp.net
  14. passing multiple values in intent
  15. passing multiple values in query string in jquery
  16. passing multiple values to a variable in sql
  17. passing multiple values in cucumber
  18. passing multiple values between components in angular

I'm working through a tutorial on how to create a restful api using express and mongoose. I'm understanding everything except for this bit right here import mongoose from 'mongoose'; import ...

I'm working through a tutorial on how to create a restful api using express and mongoose. I'm understanding everything except for this bit right here import mongoose from 'mongoose'; import ...

  1. export default javascript object
  2. export default javascript es6
  3. export default javascript vue
  4. export default javascript example
  5. export default javascript module
  6. export default javascript array
  7. export default const javascript
  8. import export default javascript
  9. export default variable javascript
  10. export default new javascript
  11. export default meaning javascript
  12. export default enum javascript
  13. export default syntax javascript
  14. export default json javascript
  15. use export default javascript
  16. export default statement javascript
  17. export vs export default javascript
  18. export default arrow function javascript
  19. export default new class javascript
  20. javascript export default and named

Kindly visit this link. RegEx Golf Here it wants me to match a few set of words and a few must not be matched. The problem is that it is not allowing me to use $ sign. I am not able to figure out ...

Kindly visit this link. RegEx Golf Here it wants me to match a few set of words and a few must not be matched. The problem is that it is not allowing me to use $ sign. I am not able to figure out ...

  1. regular expression match any character
  2. regular expression match string
  3. regular expression match python
  4. regular expression match word
  5. regular expression match number
  6. regular expression match exact string
  7. regular expression match anything
  8. regular expression match multiple words
  9. regular expression match space
  10. regular expression match whitespace
  11. regular expression match period
  12. regular expression match newline
  13. regular expression match substring
  14. regular expression match javascript
  15. regular expression match parentheses
  16. regular expression match end of string
  17. regular expression match special characters
  18. regular expression match all characters
  19. regular expression match group
  20. regular expression match character