Reputation:
I have this variable in javascript:
var datos = '<input type="hidden" name="i_txt_Prod_Code" value="Foo_Bar" tabindex="1">01080';
I need get the text 01080
from this, ignoring the hidden input
or any other input
tag.
var text = data.text(); //I used this but it did not work
if (data.match("<input")) {
var datos = $(data);
datos.find("input[type=hidden]").each(function(index) {
$(this).remove();
});
data = datos.html();
}
not duplicated @HereticMonkey pls read the post first. i am using jquery no javascript pure. o EMC structure.
Upvotes: 1
Views: 65
Reputation: 337560
Assuming you cannot access the input
, for whatever reason, the simplest way to achieve what you require would be to create a jQuery object which is a div
that contains the HTML you have in the datos
variable. Then you can simply call text()
on this div
:
var datos = '<input type="hidden" name="i_txt_Prod_Code_01080" value="01080" tabindex="1">01080';
var $datos = $('<div>' + datos + '</div>');
console.log($datos.text());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Upvotes: 3