I need a very specific selector for jquery [closed] - javascript

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.

Related

Change HTML attribute in JavaScript [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 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;">

How to build string with Bullet format [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 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>

Get div value using jquery or js [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 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 :)

How to store which child was clicked in a variable? [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 8 years ago.
Improve this question
How would I go about getting which child was clicked when the container is clicked? Whichever child is clicked to store that in a variable?
w
html:
<div class="cont">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
</div>
By finding the clicked div inside .cont
$(".cont div").click(function(){
var clicked = $(this);
})
FIDDLE
You can use event.target
$('.cont').on('click',function(e){
console.log(e.target.nodeName);
console.log(e.target.className);
});

Using jQuery or JavaScript to wrap a <span> with an <a> [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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
Improve this question
Here is my HTML:
<div class="productAttributeRow productAttributeConfigurablePickListSet" id="6921e34863c90e71a28b72aaa26e1af4">
<div class="productAttributeLabel">
<label for="c63471e76af04e3ff10e3b568d54e012">
<span class="name">Add Matching Panties (6905):</span>
</label>
</div>
<div class="productAttributeValue">
<div class="productOptionViewRectangle">
<ul class="list-horizontal">
<li class="
option
">
<label for="e0eebcbec82d5048b186e5683668a888">
<input type="radio" class="validation" name="attribute[1361]" value="1044" id="e0eebcbec82d5048b186e5683668a888">
<span class="name">XS</span>
</label>
</li>
<li class="
option
">
<label for="7d7b61c404930891d9d027ef9da67a14">
<input type="radio" class="validation" name="attribute[1361]" value="1045" id="7d7b61c404930891d9d027ef9da67a14">
<span class="name">S</span>
</label>
</li>
</ul>
</div>
</div>
What I am trying to do is put an a tag around the span tag inside the first label tag with JS after the page loads. I am using a CMS that doesn't allow changing this kind of stuff directly but it can be changed with JS once the page loads.
I am not really sure where to even start with this one, I am still not very experienced with JS. Thanks!
You can use jQuery's wrap method.
$('span.name:first').wrap('');
If using jQuery:
$('.productAttributeLabel span').wrap('');
just like yourspan.wrap('');
$('span').wrap('');
Try:
$(".productAttributeRow").find("label:first span").wrap("<a href='somelink'></a>");

Categories