Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
ajax worked 2x.
please see this
If you are using a function inside the template, it generally will run twice times. That is the way AngularJS ensures the function was ran.
You can see the same happening in this JSFIddle example.
HTML:
<div ng-app>
<div ng-controller="ExampleCtrl">
{{hey()}}
</div>
</div>
JS:
function ExampleCtrl($scope) {
$scope.hey = function() {
console.log('here i am');
}
}
So, what to do?
Do not load the data using a function in the template, load it directly when the controller is initialized. As in this example.
function ExampleCtrl($scope, $http) {
$http.get(...);
}
PS: are you not using the get method from jQuery, yep? Please. AngularJS has your own http methods. See here.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have button with id = btnadd And java script file “myscript” which is referenced in layout page.
I want this function to fire on button click but this doesn’t happen. Could anybody tell me what is the error here?
View script like this:
myscript java script file like this:
Use this code instead:
$(document).on("click", "#btnaddd", function() {
alert("click");
});
If it still does not work then you might have used the same ID btnadd for two different elements and JQUERY only matches the first one.
Maybe multiple elementes with de same id, you can see this code at jsfiddle.
$(document).ready(function() {
$('#mybt').click(function(){
alert('s')
})
});
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I cannot get jquery to change the text of a div. I have gotten the code to work on jfiddle but on the live site it is not being detected. I have even tried to add the function to (document) click so it ensure the function runs.
$(document).click( function () {
var ptime = $('#vaptimelineblock0').text();
if (ptime == "07:00 PM") {
$('#vaptimelineblock0').text("7:15 pm");
}
});
The live project is located
http://ecofreshdrycleaners.com/component/vikappointments/?view=servicesearch&id_ser=2
EDIT:
Here is the jfiddle working
https://jsfiddle.net/cts5bfud/
As already said in comments you need to fix error Uncaught TypeError: Cannot set property 'value' of null
Cause of that error is this code:
document.getElementById("couponkey").value=document.getElementById("couponcode").innerHTML;
You don't have element with id 'couponkey'.
Remove this code and it all works fine (or set element with that id properly).
Use this:
$('#vaptimelineblock0').html("7:15 pm");
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm using v1.5 of angularjs.
My problem is that whenever I try and animate a directive, especially with jquery, the directive doesn't budge.
Mine
https://jsfiddle.net/3zbeoyvL/
Im having a hard time implementing the angular js but its based off of:
Example
http://jsfiddle.net/V2x6s/3/
It looks like you are trying to generate your HTML twice, one in the HTML itself and the other in the 'template' part of your directive. I'd recommend just showing your projects in the HTML directly since you are using ng-repeat:
<div class="projtrack" id="projtrack" ng-repeat="project in projects">
<div projects-info class="projcontainer"><img class="boximg" ng-src="{{ project.img }}"><p> {{ project.description }}</p></div>
</div>
Then you can make a directive that is an attribute, which can contain the jquery you want to trigger for the element with that attribute. Notice the div with class 'projcontainer' has an attribute 'project-info'.
app.directive('projectsInfo', function() {
return {
restrict: 'A',
link: function( scope, element, attr) {
// put your jquery here
// eg
element.show();
}
};
});
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Hi i want to shrink and image and then resize it while keeping it in the same place(centerd in the page) i would like to do this using javascript. I want this to happen on a onclick event. If you need to see my code its here http://cannonmc.net/ .
For more of an idea of what i want/need look at http://orteil.dashnet.org/cookieclicker/ i want to do the same to my image as what happens when you hover/click on that cookie :).
Thanks
Luke.
I made a very simple example for you, I hope this helps.
var image = document.getElementById('image');
image.onmousedown = function() {
image.style.width = "47%";
};
image.onmouseup = function() {
image.style.width = "";
}
Would be all JavaScript needed, with the additional CSS.
Working example here:
http://jsfiddle.net/zy96xqc7/2/
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
i cant get the LcloseNav to work.
heres my code i used.the KclosNav work in this code but the LcoseNav does not, seperately they work but joined seems im doing something wrong here, please help with this.thank you.
<div id="KmySidenav" class="Ksidenav">
×
</div>
Hi Gareth you should have a function that call both KcloseNav and LcloseNav
then your html should be something like this:
<div id="KmySidenav" class="Ksidenav">
×
</div>
<script>
function closeNavs() {
KcloseNav();
LcloseNav();
}
</script>
It's better to use eventListener
I would do it this way - Change <a> to a button.
<div id="KmySidenav" class="Ksidenav">
<button type="button" class="Kclosebtn">×</button>
</div>
Add event listener
document.querySelector('.Kclosebtn').addEventListener('click', (e) => {
KcloseNav();
LcloseNav();
});
Here's explanation:
We are using querySelector to get .Kclosebtn button. Next, we are adding click eventListener. And when someone clicks on it, it will invoke KcloseNav() and LcloseNav() functions