Change .text() of a div not working [closed] - javascript

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");

Related

function to fire on button [closed]

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')
})
});

Event listeners on chrome extension class of buttons doesn't seem to work, or the action of the listener doesn't work? [closed]

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 am trying to make a chrome-extension popup-window whereby an user can add a specific tab's URL or delete one or delete all. The delete all works fine, the add URL does the trick too. However, the 'delete one link' doesn't work at all and I have really been struggling with that department. I hope someone could help me out with this one because I don't know what the problem is. Here are the files:
popup.js: gist.github.com/kobrajunior/4852f85ae18cfb9edbe542a820b8c107
popup.html: gist.github.com/kobrajunior/1c26691734c19391c62dc336ed2e1791
manifest.json: gist.github.com/kobrajunior/78acda830c2d1c384333542422f1494d
I have read on other posts that it may be because the getElementsByClassName doesn't return a 'real' array by which you can manipulate things with functions, if that's true, than I'm all out of tools to solve this one.
The 'X' button doesn't work :
Clear everything buttons works as expected :
In your removeMe() function you have to remove your DOM element from its parent element. Something like this:
function removeMe(i) {
// remove it from the DOM
var list = document.getElementsByClassName('items');
list[i].parentNode.removeChild(list[i]);
list.splice(i, 1);
// remove it from chrome-storage
chrome.storage.local.get({urlList:[], titleList:[]}, function(data) {
urlList = data.urlList;
titleList = data.titleList;
urlList.splice(i, 1);
titleList.splice(i, 1);
// update chrome storage
saveList();
});
}
Or you could just use your main list id:
document.getElementById("list").removeChild(list[i]);

Angularjs: Ajax works 2x. Please Help me [closed]

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.

Javascript delay/resizing [closed]

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/

Storing a reference to an element dynamically added by append [closed]

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 have added a new element dynamically through jQuery like this:
var elem = $('#unique').append($('<span>').attr('data-rollNo', i));
Now I need to use this element after this to add something to it. Is there a way I can store a reference to this element here, so I done need to search the entire DOM every time I edit this?
Use appendTo method instead of append:
var $span = $('<span>').attr('data-rollNo', i).appendTo('#unique');
Now, span is appended and you also have a reference to this new object.

Categories