Why isn't my Jquery closest function working [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
So I have this function:
var test = $('#currentCat').closest('div');
alert(test);
And here is the HTML
<div class="collapse" id="26">
Hoodies (6)
</div>
But instead of giving me HTMLDivElement I get Object and it's not working

var test = $('#currentCat').closest('div');
jQuery does not return DOM elements. It returns a jQuery object, which is also an array, which CONTAINS DOM elements.
Do this:
var $list = $('#currentCat').closest('div');
var element=$list[0]; // Get first item from the array
console.log(element);
Pro debugging hint:
Next time you have a question like this, examine the contents you're looking at.
Had you done a console.log(test), you could have seen it was an array (or array-like) structure.

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>

$(Element).outerWidth() is returning element's DOM instead of width [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 7 years ago.
Improve this question
I have a div which outerwidth () returns the selector itself in an array
For $('.slidePopup').outerWidth() its returning like this
<div class=​"slidePopup">​
​......​
<div class=​"sildeInside">​ ​</div>
​</div>​
Has someone else faced the same issue?
It seems this is an existing bug and fixed in older version.
https://bugs.jquery.com/ticket/12491
Please check whether you are using latest version of jQuery. If not consider upgrading to latest version of jQuery or pass "false" as argument as mentioned in the link

How to append data value to dynamically created div? [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 7 years ago.
Improve this question
I'm attempting to associate a data value with a div created dynamically, however I have not been able to get this to work. I've tried looking around online but can't seem to adapt any examples to fit my problem. If anyone could help I would be very appreciative. The error I'm getting says that:
.data is not a function
If I try putting the $ operator in front control just passes right through my block of code and nothing happens.
var container = $("#container");
('<div class="orb"></div>').data(num).appendTo(container);
It works well:
var $container = $('#container');
$('<div class="orb"></div>').data('num', 123).appendTo($container);
console.log($('.orb').data('num'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="container"></div>
What is your problem?

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)

Categories

Resources