I'm using a simple .load() function from Jquery and I can't seem to make it work. Nothing happens when I click my DIV. My alert TEST does work.
<div class="ing">CLICK HERE</div>
<div id="overlay3-content"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).on('click', '.ing', function(e){
$("#overlay3-content").load('content.html');
// window.alert("test"); THIS WORKS
});
</script>
the page content.html just has the following:
<html>TEST TEST TEST</html>
JS FIDDLE: https://jsfiddle.net/37ukdrLf/
Any ideas
you are loading the model using either file:// or C:/, which stays true to the error message as they are not http://
So you can either install a webserver in your local PC or upload the model somewhere else and use jsonp and change the url to http://example.com/path/to/model
Answer taken from
HERE
try this:
$(document).on('click', '.ing', function(e){
$( "#overlay3-content" ).load( "content.html", function() {
alert( "Load was performed." );
});
});
Related
I have the following code in my cshtml file.
<div style="display:none">
<div id="EditFancy" class="fancybox-infobar">
//Some not relevant input fields.
</div>
</div>
I'm trying to activate/show that fancybox from a javascript which is included at the top of the cshtml file.
However I'm able to activate/show it from a link within the same cshtml file. With the following code:
asd
<script type="text/javascript">
$("#btnForm").fancybox();
</script>
Help will be greatly appreciated.
You could create your own click handler using event-delegation that opens fancybox, for example:
$( "body" ).on( "click", "btnForm", function() {
$.fancybox.open({ src: $(this).attr('href'), type : 'inline' });
});
function viewproperty(){
$.fancybox.open({
src : '#propertyInfo'
});
}
This code is for the latest version of facncybox.
If you use jquery try to wrap the code with $(document).ready() function or use window.onload() javascript function
Used jQuery.fancybox.open(jQuery('#btnForm')); to open the fancybox from the javascript.
I'm new to JQuery and my problem is that I have a button in a modal such that when I click it, a JQuery script is run. Pieces of code so far:
<a id="submitMe" class="btn btn-default btn-primary">Submit</a>
$(document).ready(function (){
$("#submitMe").click(function(){
alert("Something to alert");
});
});
Thanks for all your help!
Firstly, make sure you've included jQuery properly. You should download jQuery and place it in you folder and import it at you html source or use below inline query src definition to access the library online.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
Secondly, if your anchor has been added dynamically to the DOM, you need to use event delegation:
<script>
$(function() {
$(document).on('click','#submitMe',function() {
alert("Something to alert");
});
});
</script>
I put this code:
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.0.min.js'></script>
<script type="text/javascript">
$(document).ajaxStart(function() {
$("#loading-image").show();
});
$(document).ajaxStop(function() {
$("#loading-image").hide();
});
on the top of the page...
and I have HTML:
<body style="">
<div id="loading-image" style="width:100%; height:100%; background:#ccc; display:none;"></div>
But I dont see ID loading image on ajax... What can be a problem here?
From the limited amount that you posted, it doesn't look like you're actually making an AJAX request. http://jsfiddle.net/volte/A66C8/
Try then making an ajax call when the page loads:
$.ajax({
url: "test.html",
context: document.body
});
Disclaimer: I have not tested this. Pulled from http://api.jquery.com/jQuery.ajax/
In addition, make sure you wrap those methods in an onload. Most people do:
(function() {
//... your code here ...
//... will be run on load...
});
The code doesn't seems to have anything wrong, make sure that those methods are in fact beeing called whenever you use ajax, put a breakpoint in the element inspector. Also check if when you manually remove display:none from the "loading-image" div you can see it on the screen, just to be sure.
i'm trying this code:
<script type="text/javascript">
$('#ooo').click( function() {
alert("jadner");
});
<script>
prueba
I expected it shows the alert when i click on "prueba", but it doesn't show anything..
Regards
Javi
You need to bind the event only after the DOM finishes loading. Wrap your code inside $(document).load() event like this:
<script type="text/javascript">
$(document).ready(function() {
$('#ooo').click(function() {
alert("jadner");
});
});
</script>
1 - Make sure jQuery has been included.
2 - Make sure your click handler is in a $(document).ready(function() {...}); block.
See:
http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
You have to either reverse the order of the tags, i.e. put the script after the link:
prueba
<script type="text/javascript">...</script>
or wrap the code in a $(document).ready() callback:
$(document).ready(function(){
$('#ooo').click( function() {
alert("jadner");
});
});
The problem: When your JS is executed, it tries to find the element with ID ooo which does not exist yet. Parsing is always from top to bottom. So the script gets executed before the link element is created.
Add return false; below the alert. and like Nanne says, make sure you've got jQuery loaded properly
should be </script> not <script>
use document.ready()
<script type="text/javascript">
$(document).ready(function(){
$('#ooo').click( function() {
alert("jadner");
});
});
</script>
prueba
Try the following code.
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script language="javascript">
$(function()
{
$('#ooo').click( function()
{
alert("jadner");
});
});
</script>
prueba
I am using thick box 3.1 to load a pop up. It working well by using in the following way:
TEST
If we click on the TEST now then the popup is working well and good.
Now my prob is: I need to call this popup in form load using JavaScript.
I do something like below:
<script type="text/javascript">
window.location.href = "filename.php"
</script>
it's just redirecting to that particular file. But not showing in the pop up.
What is the possible way?
thanks in advance
Try this:
Test
<script type="text/javascript">
$(function(){ // On DOM ready
$('#openOnLoad').click();
});
</script>
You can do this without changing your markup, like this:
$(function() {
$('a[href=filename.php]').click();
});
TEST
<script type="text/javascript">
$("#UniqueIdForThisLink").click();
</script>