I have a table where I want to get the value of data-url
from within a <td>
-tag. The content of the table gets first populated via $.ajax GET
. Then I use the complete
-function to log onto the console the values of data-url
. The result is undefined
.
$(document).ready(function(){
$.ajax({
type: "GET",
cache: false,
url: "http://localhost:80/server/api/v1/files",
success: function(data){
if (data.error) {
console.log(data.error)
} else {
$("#t1").append(data);
}
},
error: function(data){
},
complete: function(data){
console.log( $('#t1 #f1').data('url') );
}
});
The table first looks like this:
<table id="t1"></table>
After the Ajax call it looks like this:
<table id="t1">
<tr>
<th>
Name
</th>
</tr>
<tr>
<td>
<a id="f1" data-url="test" href="/Logo.jpg">...</a>
</td>
</tr>
</table>
What could be the correct way to get the value of data-url
in your oppinion?