I have a sortable where it was created with loaded from JSON files. Now I want to delete an item.
I receive from a textarea the element name that I have to cancel.
I save in a variable namdel
.
With a for loop I am going to compare this variable with the name of the sortable.
The HTML code of the sortable:
<div id="sortparam">
<ul style="" class="ui-sortable" id="sortable">
<li style="" id="1" class="ui-state-default"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Singular sensation</li>
<li style="" id="2" class="ui-state-default"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Beady little eyes</li>
<li style="" id="3" class="ui-state-default"> <span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Little birds </li>
</ul>
</div>
The problem is how to read the items because if I read with:
var contapara=1;
var l = document.getElementById(contapara).innerHTML;
alert(l);
The program write in alert window:
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Little birds
I want only Little birds
.
var contapara=1;
var regex = /(<([^>]+)>)/ig;
var l = document.getElementById(contapara).innerHTML.replace(regex, "");
alert(l);
Regex is our friend :)
Try this:
var contapara = 3;
var l = $.trim($('#'+contapara).text());
alert(l); // Little birds
Instead of using document.getElementById
, I'm using jQuery to get the element. I'm also using .text()
(innerText
or textContent
) instead of .html()
(innerHTML
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With