JQuery select text from anchor [closed] - javascript

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've building a nodejs app and using jquery in it. I try to get the text from a anchor from an nested list:
<ul class="someClass">
<li>
Anchor Content
</li>
</ul>
My JQuery Code to get the content is:
$('#someClass').find('a').text();
Unfortunately it isn't working. Any ideas?

Use this
$('.someClass').find('a').text();
Use the class selector. Until now, you're just using the ID selector. In jQuery . is the class selector. In HTML you're using the class not the ID. So that code won't work.
For more on jQuery selectors: http://api.jquery.com/category/selectors/

Related

innerHTML update value but HTML rendering isn't changed [closed]

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 misunderstand a JS Behavior, I want to update a td content in my HTML. So I created an anchor with onclick attribute.
When I update .innerHTML, the content is updated on javascript side, but is not rendered. I don't understand why.
<td class="data" id="<?php echo 'data_'.$_data['code']; ?>">A value</td>
document.getElementById("data_sku").innerHTML = "myNewValue";
After this, my HTML rendering doesn't change but when I use
document.getElementById("data_sku").textContent
I get "myNewValue";
I'm not comfortable with JS/Ajax behavior, just I don't understand why in this case, it's not working but in some other cases, it works.
I think that you have multiple elements with the same id in the document.
In such case you are changing and getting by the script only the first of them, but on the screen you can be looking on the other one, so see no changes observable from script.
document.getElementById("data_sku").innerHTML = "New content";
console.log(document.getElementById("data_sku").textContent);
<div id="data_sku" style="display: none;">First</div>
<div id="data_sku">Second</div>

jquery change css on radiobutton checked [closed]

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
below i have my fiddle which i want to change the text color when the radio button is selected. However i cant get it to work. at the moment it isnt firing at all and i cant get the div css to change.
$(".package-container").click(function () {
$(this).closest('.radio-group-row').find('.package-title').removeClass('highlight');
$(this).find('input:radio').prop('checked', true);
$(this).find('.package-title').addClass('highlight');
});
http://jsfiddle.net/46jGT/3/
EDIT
Thanks, it does work with the JSFiddle, but in my .net project i cant get this peice to work. i have jquery 1.9 referenced at the bottom on the master page with this code on the control page.
As mentioned in comments, you're missing the jquery library. Your code is working fine as it is once the library is added

How to click a link using jquery or javascript? [closed]

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 have a link:
Manage Lists
I want to "click" this link using jquery or javascript. I've tried:
$("#panel2-2").click(function(){});
$("#panel2-2").trigger('click');
It doesn't work! How can I do a click like this using javascript?
You need to use the jQuery attribute equals selector.
Description: Selects elements that have the specified attribute with a value exactly equal to a certain value.
For your case, you would use something like this:
$( "a[href='#panel2-2']" ).click();
You need
$('[href="#panel2-2"]').trigger('click');
or
$('[href="#panel2-2"]').click();

How to pass javascript variable in class? [closed]

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 am writing a code for quiz,whenever one option is selected by the user from out of four option,i want to alert. I have something similar to my code here:-
<label class="alert optiona">
</lablel>
I am having value
data.correct="optiona";
I need to send pass the value in javascript.When i am passing following syntax , it doesnt send the value of data.correct.
$(".alert "+data.correct).attr("class", "alert alert-"+ data.mode);
You're missing the dot in the selector and you have a space which means that the second class applies to a descendant of the .alert element.
Change
$(".alert "+data.correct)
to
$(".alert."+data.correct)

Very simple jQuery UI tooltip not working [closed]

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 replicated the example of this site:
http://jqueryui.com/tooltip/#default
Html:
<h3 title='this is the title of hello world'>hello world</h3>
JS:
$(document).ready(function() {
$(document).tooltip();
});
But it's still shows the regular tooltip only.
JSFiddle with added CSS resource:
http://jsfiddle.net/HjPtJ/
As you can read here http://api.jqueryui.com/tooltip/ the tooltip widget is added in jQuery UI version 1.9, the JSFiddle has jQuery UI 1.8 added.

Categories

Resources