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 6 years ago.
Improve this question
I am trying to display string as
. string1
. string2
. string3
By using Append function of Jquery how to build string with bullet format.
Seeing as html lists are set up using ul and li tags, we can create a html list as follows:
<ul class="myList">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
To append to it using jQuery:
$(".myList").append("<li>New Item</li>");
See the following JSFiddle to see it in action: JSFiddle -
That code adds an item to the list after 3 seconds, so you can see it being appended.
<ul style="list-style-type: normal;" id="list"></ul>
<script>
$('#list').append('<li>string1</li>');
</script>
Related
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 I change the class attribute in my HTML to "night nosmoke" using JavaScript?
<div id="imperium" class="day nosmoke" style="margin-left: -800px; margin-top: -600px;">
I've tried copying the jspath then look at innerHTML but that just brings other stuff up.
I guess this is what you mean. Remove day class and add night class to the element:
document.getElementById('imperium').classList.remove('day');// <---- Remove day
document.getElementById('imperium').classList.add('night'); //<---add class night
console.log(document.getElementById('imperium'))
<div id="imperium" class="day nosmoke" style="margin-left: -800px; margin-top: -600px;">
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
What I need to get value "Bra" inside the second li, i didn't use clas category64 because the class change every page.
<div class="breadcrumbs">
<ul>
<li class="home"><li>
<li class="category63">
Panty
<span>/ </span>
</li>
<li class="category93">
<a href="http://asdasd.com/xyz" title=>Pierre Cardin</a>
<span>/ </span>
</li>
<li class="category64">
<strong>Bra</strong>
</ul>
</div>
I have problem to get the value,
if i get the value on 2nd li , why the output "Pierre Cardin/", the output have "/", how to not include the "/" ?
Use nth-child selector, it matches the element for given index
var text = document.querySelector('.breadcrumbs li:nth-child(2)').innerText;
alert(text);
<div class="breadcrumbs">
<ul>
<li class="category63">
Panty
<span>/ </span>
</li>
<li class="category64">
<strong>Bra</strong>
</ul>
</div>
You can try:
var a = document.querySelectorAll(".breadcrumbs li")[1].innerText;
alert(a);
demo
Used to this code in jquery
var code = $('.breadcrumbs > li:nth-of-type(2) strong').text(); alert(code);
You have several option:
First: Attach an id to the <strong> tag
<strong id="myId">Bra</strong>
and get the value with:
var text = document.getelementById('myId').innerHTML;
Second: Use getElementsByTagName() to get it as:
var text = document.getelementByTagName('li')[1].innerHTML;
But personally I do not recommend it, since the value of the li could vary if you add more li tags to the DOM tree above the one you want to get.
It could be possible add the id attribute to the li instead than to the strong tag, but then you will nned to get the firstchild before get the innerHTML as:
var text = document.getelementById('myId').firstChild.innerHTML;
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 7 years ago.
Improve this question
A have e3 and e2 divs, and parent div e.
There is too many e divs on the page.
How can I get e3 div value when I click on div e2?
Thanks.
There is no value attribute for div. You could get the innerHTML through javascript.
var divValue = document.getElementById('e3').innerHTML;
Let me first tell you how i understood the question. This is kind of how your html is structured:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="e">
<div id="e2">
i am e2 text
</div>
<div id="e3">
i am e3 text
</div>
</div>
<div id="e">
another e text
</div>
And this is the js code that will give the content of the e3 div when the user click on the e2 div.
$(document).ready(function(){
$("#e2").click(function(){
alert($("#e3").html());
})
});
Hope this helps :)
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 would like to make a box with 3 options (2013, 2005, 2004) that are all hyperlinked to their own seperate jquery slider image galleries. I want it so that say when you click 2013, the 2013 image gallery appears and then when you click 2005, the 2005 image gallery appears instead.
I dont know if i should be using 'click event listeners' or just using html. I am new to coding and would appreciate as much help. Thanks.
Example:
jsFiddle
If you are using a thirdy part plugin to provide gallery functionality you can solve your problem this way:
create a second container box, and put the 3 different galleries into the container, but hidden.
example:
<div class="select-gallery">
<ul>
<li data="gallery1">2013</li> <!-- the data attribute links the list element to it's related gallery -->
<li data="gallery2">2005</li>
<li data="gallery3">2004</li>
</ul>
</div>
<div class="gallery-container">
<ul id="gallery1" class="is-hidden gallery">[...]</ul>
<ul id="gallery2" class="is-hidden gallery">[...]</ul>
<ul id="gallery3" class="is-hidden gallery">[...]</ul>
</div>
Then with javascript, (i'm assuming you are going to use jquery to speed up)
jQuery Framework, you can attach an event handler to the click event of the select-gallery list elements to show any of your galleries, this way:
$(document).ready(function () {
$(".select-gallery").on("click", "li", function () {
var $data = $(this).attr("data");
$(".gallery").css("display", "none");
$("#" + $data).fadeIn();
});
});
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
Hi guys i have a problem with a selector of jquery.
I have this Html:
<div id="Id_Province_chzn">
<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1">
<span> + this.default_text +
</span>
<div>
<b></b>
</div>
</a>
<div class="chzn-drop" style="left:-9000px;">
<div class="chzn-search">
<input type="text" autocomplete="off" />
</div>
<ul class="chzn-results"> **<-- I need to access here**
</ul>
</div>
I need to append <li> to the <ul> tag, but i don't know how to access.
My idea is to do something like this:
var ul = $(??);
ul.append('<li>some text</li>');
Sorry my english and thanks for your help.
use the class selector
$('ul.chzn-results').append(....)
$('ul.chzn-results') should do it.