This function loads HTML via AJAX and performs a search/scrape using find()
. It works well if the server name is unique. However as per the example below, if I make a search for server10
it will print out server109 & amer
since it appears first in the HTML.
Is there a way I can use to find exact match and console log server10 & apj
. Have tried various method but didn't work. Kindly suggest or provide example.
function vm(vm_server) {
$.ajax({
url: 'http://someurl.com',
dataTpe: 'html',
type: 'GET',
success: function(data) {
var server_name = $(data).find("td:contains(" + vm_server + ")").text();
var location = $(data).find('td:contains("' + server_name + '")').next().text();
console.log(server_name)
console.log(location)
}
});
}
someurl.html
<tr>
<td>server109</td>
<td>amer</td>
</tr>
<tr>
<td>server10</td>
<td>apj</td>
</tr>
<tr>
<td>server102</td>
<td>apac</td>
</tr>
<tr>
<td>server105</th>
<td>emea</td>
</tr>