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('');
});
});
Related
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".
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>
This question already has answers here:
'$' is undefined
(2 answers)
Closed 8 years ago.
What I want to do with my code is to use information from an input box in other parts of the webpage or data validation. From my understanding, I have to use something to the effect of, for example:
<script>
var value = $('input').val();
alert(value);
</script>
But when I try to use this block of code, Chrome's console is telling me the error message "Uncaught Reference Error: $ is not defined," but I don't know why. If it helps, the following is my code:
JS:
click = function() {
var password = $('input#password').val();
alert(password);
};
HTML:
<input type="text" id="password">
<input type="submit" onClick="click();">
If anybody could please explain why this error is occurring, I would greatly appreciate it. Thanks in advance!
$() is a javascript function that's defined by the jQuery library.
(It's just like any other function - foo(), for example... it's just named with a single $)
The example you're working from looks like it's written to use jQuery, so you need to make sure you include jQuery on your page before you run your code.
Try adding this line at the top of your document (in the <head> section if possible):
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
There are other libraries that sometimes use the $ name as well - prototype, for example - and having multiple libraries fighting over the $ name can sometimes give you similar looking errors. There are techniques you can use to help avoid conflicts like that.
try this
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
$(document).ready(function(){
var value = $('input').val();
alert(value);
click = function() {
var password = $('input#password').val();
alert(password);
};
});
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
JavaScript query string
...Riight. I found the answer to my problem. I'd forgot to add '' around some jsp scriplet tags in my popup window code. Because of this values that should've been strings weren't handled properly.
I'll flag this question for moderator attention. The only thing one can learn from this question is to pay attention when using jsp scriptlets.
I want to open a popup from my .js code using window.open(). I have a couple of parameters that I need to pass to this popup. I'm surprised it's not as simple as I would've thought, I've tried searching for answers but all I found were solutions that were quite complicated - I hope there's a simple answer.
There's a multitude of ways I've tried doing this, but this is how I think it should work..
window.open('../common/MapPopup.jsp?current='+currentPosition+'&areas='+sAreas, 'mywindow', 'width=600,height=450,scrollbars=yes');
I'm at a total loss. Could it be that window.open just doesn't work in this situation?
edit: Currently my page behaves like this. The user presses a form button, which launches a query into our database. From this data a DataTables table is created. As the DataTable is being initialised, so is a piece of jQuery code. I'm using jQuery to open a popup when the user clicks on a row in the DataTables table.
renderReport: function(response){
$('#requestDataContainer').html(response);
oTable = $('#dataTable').dataTable({
"bPaginate": true,
--snip-- //DataTables init
});
var sProcedures = new Array();
var sAreas = new Array();
var sCurrentPosition = null;
$('#dataTable tr').click(function(){
var sCurrentPosition = oTable.fnGetData(this,9);
if(sCurrentPosition!=null){
$('#dataTable').find('tr').each(function(){
var foo = oTable.fnGetData(this);
if(foo!=null){
if(foo[8]!='null')
sAreas.push(foo[8]);
if(foo[7]!='null')
sProcedures.push(foo[7]);
}
});
}
window.open('../common/reportMapPopup.jsp?procedures='+sProcedures+'&areas='+sAreas+'¤t='+sCurrentPosition, 'reportMap', 'width=600,height=450,scrollbars=yes');
});
},
I have to admit, I'm quite newbish when it comes to webcode. I'm kind of learning on the go, so the terminology might be new to me and I could be doing things in a really silly way. It could be that I found the answer when I was looking for it on the web, but just didn't realise it.
If the query string in your url gets passed to the window you should be able to access those parameters from the window using JS using the location object(http://www.w3schools.com/jsref/obj_location.asp)
If you have access to the actual page - can you not retieve the params using jsp?
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