Debugging not showing the proper result [duplicate] - javascript

This question already has an answer here:
innerHtml command not working Advise please
(1 answer)
Closed 6 years ago.
I am trying to learn the javascript debugging and I am followint the article here[linke here][1]
[1]: http://meeech.amihod.com/getting-started-with-javascript-debugging-in-chrome/ I was able to follow along the tutorial.My code is
<script>
var value="hang";
function test(){
setInterval(function(){
switch(value){
case'hang':
document.body.innerHtml="Hang in there";
break;
case'up':
document.body.innerHTML="Up";
break;
default:
document.body.innerHTML="No good!";
}
},1000);
};
</script>
Ater inspecting in debugger,it shows that it reached to document.body.innerHtml="Hang in there";But my html page isnot showing the output Hang in there
Though it may seem simple question, I am not getting into it. Please help.
Also I cannot find Add to watch option on right click as stated in tutorial.

JS property names like innerHTML are case-sensitive. Try changing it to ….innerHTML="Hang in there".

Related

How to link a url to a button in javascript [duplicate]

This question already has answers here:
JQuery - $ is not defined
(36 answers)
Closed 11 months ago.
I am using a WordPress website and trying to attach a url to a button using JavaScript. I have written a function to this, My function as follows.
<div class="the_course_button" data-id="3565"><div class="course_button full button">TAKE THIS COURSE</div></div>
jQuery(document).ready(function ($) {
$('#3565').each(function() {
var link = $(this).html();
$(this).contents().wrap('');
});
});
I passed my data-id '#3565' to call the function. Now I am getting nothing
What did I do wrong here?
I appreciate the help thanks so much.
That syntax you are using, is from JQuery, so the error you are getting, is problably because you haven't linked it correctly.
If you want to use JavaScript For making this, you should use document.getElementById("3565")
You will need to change more things if you want to use JavScript, but if you need to use JQuery, you should look this link https://www.w3schools.com/jquery/jquery_get_started.asp
I think you should clarify clearly on which environment you get that error.
Since I see your tag 'wordpress' so I assume you get the error in wordpress.
If so, please read this reference: $ is not a function - jQuery error
Your code should be wrapped like this:
jQuery(document).ready(function ($) {
$('#3565').each(function() {
var link = $(this).html();
$(this).contents().wrap('');
});
});

linking png image from json to html [duplicate]

This question already has answers here:
How to interpolate variables in strings in JavaScript, without concatenation?
(17 answers)
Closed 5 years ago.
As I'm sure you're about to see for yourself, I'm relatively new at coding. I've been struggling to get the png image from json file to show up on my codepen. I've already tried several suggestions I found in my Stackoverflow searches but nothing I've tried seems to work for my situation.
Here's the link to my codepen:
http://codepen.io/mbabaian/pen/MpjbZv
The code I'm trying to use to get the image at this time is:
var currentIcon = wd.current.condition.icon;
// weather icon settings
$("#current-icon").html("<img src='wd.current.condition.icon' alt='weather icon'/> ");
And here's the particular json data where the image is located:
https://api.apixu.com/v1/current.json?key=68629a769f564f9bb6450153170703&q=auto:ip
Please let me know if you need any additional information from me about this. Thanks in advance.
Simply use
$("#current-icon").html("<img src='"+wd.current.condition.icon+"' alt='weather icon'/> ");
Here is your updated codepen
You create currentIcon, use it
$("#current-icon").html('<img src="'+currentIcon+'" alt="weather icon"/>');

Trying to merge 2 pieces of code, now receiving Uncaught ReferenceError: $ is not defined [duplicate]

This question already has answers here:
Uncaught ReferenceError: $ is not defined?
(40 answers)
Closed 6 years ago.
Firstly, I want to make sure that you know that I know that stackoverflow is filled with topics related to my issue, however I have looked through them and literally none of them seem to relate to my issue.
I am a complete noob when it comes to javascript, however I am good in Googling and analyzing/adjusting free-to-use codes so that it works for me (until now...)
The initial project was a calculation form which I got to work the way I wanted it. Now I want to show a value right under the dropdown boxes in the top of the page, since each choice needs an accompanying comment.
I have literally copy-pasted a piece of code I found through StackOverflow which works perfectly fine in JSFiddle: http://jsfiddle.net/irama/ZFzrA/2/
hideAllDivs = function () {
$("#hourly").hide();
$("#per_diem").hide();
$("#fixed").hide();
};
handleNewSelection = function () {
hideAllDivs();
switch ($(this).val()) {
case '1':
$("#hourly").show();
break;
case '2':
$("#per_diem").show();
break;
case '3':
$("#fixed").show();
break;
}
};
$(document).ready(function() {
$("#project_billing_code_id").change(handleNewSelection);
// Run the event handler once now to ensure everything is as it should be
handleNewSelection.apply($("#project_billing_code_id"));
});
However, when I add it to my existing code and upload the changes, I receive the reference error in my browser and the div's under the dropdown box show by default.
My complete code: https://jsfiddle.net/ohwwzo7q/
So basically my question is where did it go wrong?
P.S. My calculator doesn't work probably because of the error, when I remove the extra code it does work again however.
You need to include jquery as a dependency to use $
You can either download a version from the jquery website, or use a CDN. Either way, it can be included like this:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>

<script> Invalid comment formatting? [duplicate]

This question already has an answer here:
Does HTML comment <!-- act as a single-line comment in JavaScript, and why?
(1 answer)
Closed 7 years ago.
I have taken on a project that someone else has worked on and I am running into a bunch of script blocks formatted like this:
<script>
<!--
$('...').live('change', function() {
if (...) {
$('...').hide();
$('...').show();
} else {
$('...').show();
$('...').hide();
}
});
//-->
</script>
They are not even the correct comment format for JavaScript.
The code still works but should I worry that this might break in the long term if I start adding to it?
Is this just blatantly wrong and should I remove all the invalid comments?
To formalize my comment.
Back in the day not all browsers supported JavaScript. To make the JS disappear it would be wrapped in an HTML comment and the browser would effectively ignore it.
This hasn't been relevant for some time now and it can be safely deleted.
It can also be left in without harm, but ew.
By way of example, this question from 2009 asks the question re: relevancy, not what it actually is.
This also means I'm old :(

how to get html from CKEditor? [duplicate]

This question already has answers here:
Get formatted HTML from CKEditor
(12 answers)
Closed 9 years ago.
I'm using CKEditor in my web app, but I don't know how to get html content from it.http://cksource.com/ckeditor
I searched online found one said using getData() method, but there is no getData() method after typing dot after the controler. Can anyone give me a sample code to get html from CKEditor controller? Thank you in advance.
To get htmlData from editor you should use the code snippet bellow:
var htmldata = CKEDITOR.instances.Editor.document.getBody().getHtml();
If this solution won't work, check if you have BBCode plugins installed.
getData() is part of the javascript API.
It seems that you are trying to do it at the server side, so you should check the specific API of whatever wrapper you are using, or just check the value in the form posted data.
Not sure how you're implementing usage of the CKEditor.
If you're replacing a textarea using CKEDITOR.replace( 'NameOfTextarea', this should work:
CKEDITOR.instances.NameOfTextarea.on( 'instanceReady', function( instanceReadyEventObj )
{
var editorInstanceData = CKEDITOR.instances.NameOfTextarea.getData();
alert( editorInstanceData );
});
Replace "NameOfTextarea" with the name of your textarea, it's used to name the editor instance.
It's a good idea to put it inside the "on instanceReady" function so you don't get an undefined error.
Joe

Categories