To delete list item from DOM [closed] - javascript

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 yesterday.
Improve this question
<ul>
<li data-item="item1">item 1<button>X</button></li>
<li data-item="item2">item 2<button>X</button></li>
<li data-item="item3">item 3<button>X</button></li>
<li data-item="item4">item 4<button>X</button></li>
<li data-item="item5">item 5<button>X</button></li>
</ul>
On clicking X button, it should delete and not remove that particular list item from the dom. And we cannot apply onclick event on X button.
I am having doubt in this. Can anyone please tell difference between delete and remove from DOM. I thought of using remove method of dom.And also, how to solve this without using onclick button.

Related

How to create an Html element again when the user clicks a button [closed]

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 1 year ago.
Improve this question
I did create a Html form tag and Html button tag.
Now I want to create again form tag when the user clicks my button
I think this is possible with JavaScript
If anyone knows please help me
Thanks
Here is a sample code. This will add the form once.
let form = document.getElementsByClassName('sample-form')[0]
//make copy of the original form using cloneNode(true). true means JS will copy all the nodes inside of the form element. It's called "deep copy".
function duplicateForm(){
return form.cloneNode(true);
}
let addForm = document.getElementById('add-form')
addForm.addEventListener('click', function(){
document.body.append(duplicateForm())
})
<form class="sample-form">
<input placeholder="Your value here"/>
</form>
<button id="add-form">Add New Form</button>

Custom hover popup in HTML/JS/CSS [closed]

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 2 years ago.
Improve this question
How would one be able to get a popup like the image below on hover of an element? I'm not sure what I should be adding in here apart from that I preferably don't want to use any other libraries apart from jquery. Please tell me if you need any code snippets or any more information!
Let's say you have said element above as a div on your page with an ID of 'cursor'. You can set the display value in your css to 'hidden', so it won't be displayed at first. When you hover over another element, you can trigger functions to display or hide said element:
<div id='hover-element' onmouseover='onMouseOver()' onmouseout='onMouseOut()'></div>
<div id=cursor'</div>
And then inside those functions:
function onMouseOver(element){
document.getElementById('cursor').style.display = 'block';
}
function onMouseOut(element) {
document.getElementById('cursor').style.display = 'none';
}
Try it :)

HTML - Calling Javascript Function with variable? [closed]

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
So I am trying to do a button and if you click on it then it calls a function called order(). So, If I'm trying to do something like this order("+<script>blablabla</script>+") then it shows me a error if I type into something between the "+HERE+" Why that? Is there any way around it?
You could always do something like this. Maybe change the divs around a bit and add a rounding system. This gives you a live update on the costs when selecting how many keys.
https://jsfiddle.net/8hube9ua/
Throw this under your select,
<span data-val="1.85">1.85</span> <!--How much each key is-->
then throw this into the script.
<script>
$('#suiface').change(function(){
var span = $(this).next('span');
span.text(span.data('val') * parseInt(this.value,10)) //multiplies the cost by the option selected
})
</script>
I'm not sure to understand, but why don't you write something like this ?
<button onclick="order()">Blablabla</button>

How do I apply a style based on a condition (return value from a function in JS)? [closed]

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 7 years ago.
Improve this question
I am using simple html and associated JS code. I have a statement like this in my html code:
<td class="ui-navigation-static-menu-holder" style="width: 147px; display: block">
I want to apply the display: block style only when a particular condition is true (say isStyleBlock() in my associated JS code).
How can I achieve that?
if(isStyleBlock()) {
elem.style.display = 'block'
}

Have HTML anchor simulating clicking a different element [closed]

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 9 years ago.
Improve this question
I have something like this:
Vehicle Info
<script type="text/javascript">
function clickVehicleTab() {
$("#vehicle").trigger('click');
}
</script>
The function gets executed, however the jQuery to click the object doesn't seem to be executing successfully. What am I missing?
EDIT:
It appears the bind on the #vehicle object is a problem. It looks like this:
$('#jsddm > #vehicle').bind('click', openVehicleMenu); //vehicle menu click event
So the #vehicle can't be programattically clicked directly the way I'm trying.
A better way to do this would be adding an id to the link and using this to listen to the trigger event. Then when this is entered trigger the click-event on the element with the id "vehicle"
Vehicle Info
$(document).ready(function(){
$("#url").click(function(e){
e.preventDefault();
console.log('TEST: clickVehicleTab entered...');
$("#vehicle").trigger('click');
}
});
If the binding is done programatically why don't you just use:
openVehicleMenu();
instead of
$("#vehicle").trigger('click');

Categories