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();
});
Related
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 2 years ago.
Improve this question
I am trying to access the below tag class="topbar"
<div id="swagger-ui">
<section data-reactroot="" class="swagger-ui swagger-container">
<div class="topbar">
<div class="wrapper">
<div class="topbar-wrapper">
I have tried this:
var x=document.getElementById("swagger-ui");
var y=x.getElementByClassName("swagger-ui swagger-container");
var z=y.getElementByClassName("topbar");
Also,
How can I set value in js? I have to set the value for input type text
<div class="wrapper"><label>Value:</label><section class=""><input type="text"></section></div>
You can do something like the following:
var topbar = document.getElementsByClassName('topbar');
or
var topbar = document.querySelector('.topbar');
try to use querySelector
var x=document.querySelector("#swagger-ui");
var c=document.querySelector(".swagger-ui");
var y=document.querySelector(".swagger-container");
You're code is almost perfect, but you need to spell getElementByClassName correctly, and add an indexer for getElementsByClassName. Try adding [0] after each getElementsByClassName function. Like this: getElementsByClassName[0]
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 8 years ago.
Improve this question
I am making a notification system and after the comment has been scrolled to i want to highlight in someway the comment specified.
I was just going to time out a background colour change but cant get it working...
Heres a fiddle:
I have commented out the scrollIntoView() as it plays havoc with the jsfiddle itself.
$(document).ready(function(){
var commentid = "comment";
//document.getElementById(commentid).scrollIntoView();
$(commendid).css('background-color', 'red');
});
That's the code, any silly reason why the background colour is not changing?
You have several issues.
You need to use a # to denote an id.
You have a typo commendid should be commentid
$(document).ready(function()
{
var commentid = "comment";
$("#" + commentid).css('background-color', 'red');
});
Add the '#'. This indicates an id
var commentid = "#comment";
You are missing '#' symbol :)
$(document).ready(function(){
$('#comment').css('background-color', 'red');
});
Try this one :
$(document).ready(function(){
var commentid = "#comment";
$(commentid).css({'background-color': 'yellow'});
});
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 9 years ago.
Improve this question
I can't figure out why the jQuery functions will not work with the html here
JS Fiddle: http://jsfiddle.net/JonaTheApprentice/E89rg/
function addItem() {
$('#list').append('<li><input type="checkbox" /> item</li>');
}
function removeItem() {
$('#list').children().filter(function () {
return this.firstChild.checked;
}).remove();
}
I don't see an element with id="list", that's what #list refers to.
I think you mean #items-listed. Changing that, and it works
I would get the value from the input id. I would also assign a click event for cleaner coding. Here is an example of your fiddle adding an item. Removing an item is just the reversal.
DEMO http://jsfiddle.net/E89rg/5/
$('#Enter').click(function(){
var Val = $('#item').val();
$('#items-listed').append('<li><input type="checkbox" />'+Val+'</li>');
});
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 9 years ago.
Improve this question
I have a contenteditable div inside jquery tab and I am trying to get the content using a
button. When I click on button a javaScript function is getting called,
inside the function I am trying to grt the content
HTML code
<div id="tab1" contenteditable="true">
<div>line no one</div>
<div>line no one</div>
</div>
JavaScript function
alert($("tab1").text());
alert($("tab1").html());
error
For text(); I am not getting any thing but for html(); it is showing Undefined
I am not able to guess whats wrong with the code...
Any suggestions...
You need to use ID indication "#"
alert($("#tab1").text());
// ^here
DEMO
See you have missed # notation for id selector and make sure to have it wrapped in $(function(){...}) doc ready handler:
$(function(){
alert($("#tab1").text());
alert($("#tab1").html());
});
jQuery expects a selector, not an id. "tab1" is a type selector, it matches <tab1> elements (which do not exist in HTML).
You can use an ID selector though: $("#tab1").
Are you using jquery?
Does it load proprely?
try this
alert($("#tab1").text());
alert($("#tab1").html());
you have to tell jquery that you are looking for an id with "#"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i looked the question
him need know $( [myc="blue"] AND ([myid="1"] OR [myid="3"]) )
that last answer is $('[myc="blue"][myid="1"],[myc="blue"][myid="3"]')
now i need use for more condition
like -> $( ([myc="blue"] OR [myc="red"]) AND ([myid="1"] OR [myid="3"]) )
please show me the way T.T
To not have to write down every possible attribute combination, use .filter:
$('[myc="blue"], [myc="red"]').filter('[myid="1"], [myid="3"]');
This selects all elements with a myc attribute with values either "blue" or "red". Then it reduces the set to the elements which also have a myid attribute with values "1" or "3".
If you invest a little of your time and have a look at all the possible selectors, you can figure out the solution for such problems on your own.
Your expression
$( ([myc="blue"] OR [myc="red"]) AND ([myid="1"] OR [myid="3"]) )
can be developed as
$( [myc="blue"] AND [myid="1"]
OR [myc="blue"] AND [myid="3"]
OR [myc="red"] AND [myid="1"]
OR [myc="red"] AND [myid="3"] )
Try this code:
$('[myc="blue"][myid="1"],[myc="blue"][myid="3"],[myc="red"][myid="1"],[myc="red"][myid="3"]')