Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two peices of code. One produces the desired result the other one doesnt.
Works:
$("#inBox" + mesh.id).html(mesh.text);
Doesn't work:
var inbox = $("#inBox" + mesh.id);
inbox.html(mesh.text);
Could someone please explain to me why one produces the desired result and the other one doesn't do anything?
edit: removed typo quote mark.
edit2: heres the fiddle. http://jsfiddle.net/ntkachov/zXGjb/
edit3: Hmmm.... It works inside the fiddle but not inside my code. Ill take a look at what else might be affecting this.
Looks like you have a typo:
inbox.html(mesh.text");
Should be:
inbox.html(mesh.text);
I created a jsfiddle that shows your example. It works fine for both cases.
You have a trailing " after mesh.text
inbox.html(mesh.text");
This should do it:
inbox.html(mesh.text);
Edit:
Added a fiddle for demonstration: Fiddle
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a problem with javascript on Wordpress!
I have to insert in my theme this pen https://codepen.io/z-/pen/OBPJKK .
HTML and css work, the only problem to fix is with javascript.
I replaced "$" in the original JS with "jQuery" and I entered this script in Theme Option> Advanced > Code Fields > Space Before head area:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.single .fusion-post-slideshow li img').each(function() {
var caption = jQuery(this).attr('alt');
jQuery(this).after('<span>' + caption + '</span>');
});
});
</script>
The problem lies in the inability to reproduce the onclick effect of the aforementioned pen.
When going to the url of the page http://www.goatsplan.com/goats-magazine/, Wordpress seems not to recognize JS, and it is as if no code has been entered. Please, how can I solve this problem and keep the same type of animation in javascript?
Thank you very much
jQuery(".option").click(function(){
jQuery(".option").removeClass("active");
jQuery(this).addClass("active");
});
Just past the above jQuery in the Footer file/Template
Its working fine--> https://prnt.sc/r04jfi
https://prnt.sc/r04jug
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to remove a list item.
I add an item in like so:
$('#btnAdd').click(function(){
var text = $('#item').val();
if(text.length){
$('<li />',{html: text}).appendTo('ul.justList')
}
});
then remove it like so:
$('#btnRemove').click(function(){
$("#justList li:last-child").remove();
});
Why does the last list item not remove? Any suggestions? Thanks so much!
I think the problem may be in your punctuation. Note the difference in punctuation between "justList" in .appendTo('ul.justList') and in $("#justList li:last-child").
ul.justList says, "Look for a <ul> with the class of 'justList'," or <ul class="justList">.
#justList says, "Look for any element with the ID of 'justList'," or <any-element id="justList">.
Classes and IDs are different, so make sure you're using the correct punctuation: . for a class, and # for an ID.
Based on your add statement I would guess that you need a remove statement like:
$('#btnRemove').click(function(){
$("ul.justList li:last-child").remove();
});
If your add statement is working then this should be accessing the same ul
Please use . instead of # while remove as well
$('#btnRemove').click(function(){
$(".justList li:last-child").remove();
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i have this link
Test
Now when i click directly on the link .. The alert get popped up in my window.
But, $("#myLink").click();
doesn't call the popup.
EDIT : I need to trigger the function inside href using jQuery
Solved --------- :
var x = $('#myLink').attr("href");
window.location = x;
Figured out..
var x = $('#myLink').attr("href");
window.location = x;
getting the href value and then targeting it .. solved the problem.
Try href="javascript:alert ('test')" or onclick="alert ('test')"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I need get a value using jquery "data()". but I need to do it by doing something like this. So please give me an idea . Thank you in advance.
//html
<div id="myid" data-cityid="Colombo" ></div>
var name = "cityid";
$("#myid").data(""+name+""); // this way not working :(
Your are trying to get attribute, use attr() for it with complete name of attribute:
var name = "data-cityid";
alert($("#myid").attr(name));
Here is demo
You try to use attr():
To get:
$("#myid").attr('data-cityid');
To set:
$("#myid").attr('data-cityid', name);
Try with attr.
$("#myid").attr("data-"+name);
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have 2 separate functionalities on one page of my site, both of which call the same Ajax function. The 2 functionalities need to be distinguishable. My solution was to pass a string (called string here) in one of the functions, such as in the following simplified example.
<script type="text/javascript">
function AjaxFunction(string) {
if (string === 'String') {
alert('You have clicked Button2');
} else {
alert('You have clicked Button1');
}
}
</script>
<button type="button" id="Button1" onclick="AjaxFunction()">Click1</button>
<button type="button" id="Button2" onclick="AjaxFunction('String')">Click2</button>
This seems perfectly fine to me. The only issue is that string is null when Button1 is clicked. I imagine there is no problem with this since the if...else takes care of any ambiguity of what to do with string. I have tested with my actual Ajax function and everything works OK, but since I am still somewhat new to coding I always imagine that stupid mistakes I am not aware of will destroy the site. Sorry for the trivial question but am I missing any performance issues, bugs, etc. with this approach? Thank you for any help!
You need to pass an empty string into the first button call. So:
onclick="AjaxFunction('')"