<script type="text/javascript">
if (SOMECONDITION) {
$("#scriptD").attr("src", "../../Scripts/A.js");
} else {
$("#scriptD").attr("src", "../../Scripts/B.js");
}
</script>
<script id="scriptD" src="" type="text/javascript"></script>
I am trying to insert a .js file dynamically ( on the condition basis). But this is not working . Can anybody tell me whats the problem here?
One way to do what you are trying is using
$.getScript()And besides, you way will work, if you place the script after the
<script>elementThis is because the script will not be able to find
scriptDon the DOM, when it is called before an element.