Last active
December 19, 2015 14:29
-
-
Save robcolburn/5969440 to your computer and use it in GitHub Desktop.
External JS w/ jQuery Data Attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var data = $('body').data(); | |
$("#thing-1").load(data.path + "resource-1"); | |
$("#thing-2").load(data.path + "resource-2"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? $path = "http://www.example.com/"; ?> | |
<body data-path="<?= $path ?>"> | |
<div id="thing-1" class="thing"> | |
</div> | |
<div id="thing-2" class="thing"> | |
</div> | |
<script src="after.js"></script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('.thing').each(function () { | |
$(this).load( $(this).data("path") ); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? $path = "http://www.example.com/"; ?> | |
<body> | |
<div id="thing-1" class="thing" data-path="<?= $path ?>resource-1"> | |
</div> | |
<div id="thing-2" class="thing" data-path="<?= $path ?>resource-2"> | |
</div> | |
<script src="after.js"></script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? $path = "http://www.example.com/"; ?> | |
<body> | |
<script> | |
var path = "<?= $path ?>"; | |
</script> | |
<div id="thing-1" class="thing"> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('#thing-1').load(path + "resource-1"); | |
}); | |
</script> | |
</div> | |
<div id="thing-2" class="thing"> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('#thing-2').load(path + "resource-2"); | |
}); | |
</script> | |
</div> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment