winter winter - 1 month ago 16
jQuery Question

after append content and invoke function in jquery

there are data page:_data.cshtml

<table id="example1" class="display table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
</table>
<a href="#" url="/data/index" save-data="default"> Save Changes </a>


there are container page

<div class=".mycontainer"></div>


when i load data in container page like this:

$('.mycontainer').append(data).on('click', '[save-data="default"]', function (event) {
load(event);
});

function load(event) {
var url = $(this).data("url");
}


question:
url == undefined

i hope the value url = "/data/index"

i can append the partial page(_data.page)

but i can not get the value.

please give me some point ,thanks!

Answer

Try changing to

$('.mycontainer').append(data).on('click', '[save-data="default"]', load);

Now without the anonymous function the arguments and this context will be correct


Also seems to be a typo in class name in html that shouldn't have a dot in it

Comments