I have a list like this in a div:
<div id="x">5,2,3,1,4,9,8</div>
How do I simply remove a given element from this list?
JQuery or JavaScript may be used.
Please note that the numbers in the list are unique and they are coming in from a database of type int(11), they are not in any sort of order.
Any help appreciated guys…
First, get the text:
Then split it:
If there’s no items, you’ll have an empty string as the only element of the array. If so, empty the array:
Now convert everything to an integer: (note that this step isn’t actually required, but if you’re doing anything else with
items, it’s nice to have)Put the item you want to remove in a variable:
Find that in the array:
If it was found, splice it out of the array:
Join the items back together:
Put it back in the element: