Reputation: 303
I tried appending content to a div using a jQuery function. It gets added if I specify the id of the div manually. If I specify the id as a argument to function, it's not working.
function addcontent(TargetDiv) {
$(TargetDiv).append('Some text here');
}
$(document).ready(function() {
addcontent('divTable');
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="divTable"></div>
hai
Upvotes: 0
Views: 28
Reputation: 11122
You need the #
prepended to the id to find it:
function addcontent(TargetDiv)
{
$("#" + TargetDiv).append('Some text here');
}
Upvotes: 2