2
I’m filling a table as follows:
$.ajax({
method: "GET",
url: "https://api.github.com/search/users",
data: { q: search, sort: "repositories" }
})
.done(function( msg ) {
jQuery.each(msg.items, function(i, users){
getRepositories(users.repos_url).done(function (result) {
var repositories = result.length;
$( 'tbody' ).append('<tr class="user"><td><a class="username">' + users.login + '</a></td><td>' + repositories + '</td>');
});
});
});
Only I need to get the value inside the element <a class="username">
, when the user clicks.
What I’ve already tried:
$( ".user .username" ).click( function() {
console.log($( this ).text());
});
And:
$( ".user" ).click( function() {
console.log($( this ).children('a').text());
});
And nothing just appears on the console, not one undefined
. =(
if you posted the button or link would already be halfway...
– Michel Simões
I don’t get your comment. @Michelsimões
– Francisco
Put the html from the button in the post man!
– Michel Simões
Try putting an example of the generated html for the whole table, so we can test here and solve the problem. o
<a>
wasn’t supposed to havehref
? Or is thecursor
by css?– Isac
@Michelsimões That’s it! I’m creating hair
append
jquery!– Francisco
@Isac O
<a>
have href or not, does not interfere with functionclick()
.– Francisco
was bad :) look at the answer if the value Voce wants is the users.login should give, but each time Voce makes an insertion of a line dynamically by JS Voce should redeclare that . click to fit the new line
– Michel Simões
@Francisco Yes I know, it was a question aside, because I thought it was strange not to have and I might not have noticed.
– Isac