Issue
there are many examples out there of how to loop through Select Options, e.g.
Iterate through <select> options
but my problem is that I have to loop through an HTML string e.g. :
var s = "<option value="0">OptA</option><option value="1">OptB</option><option value="2">OptC</option>"
How can I loop through each item please? the idea is that I have a string obtained from a dropdownlist.innerHTML, and an ID to find between all the options in the innerHTML:
GetValueFromHTML(iValueToFind,strHTML){
$(strHTML).each(function () {
var iTempValue =
var OptionText =
if (iTempValue == iValueToFind){
alert(OptionText );
}
})
}
Solution
This seems to give the result you want, you were very close. Just needed the $(this).val()
really:
function GetValueFromHTML(valueToFind ,html){
$(html).each(function () {
var val = $(this).val();
if (val == valueToFind){
alert($(this).text());
}
});
}
Answered By - Richard Dalton
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.