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>
Related
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 an html table and I want to remove a complete <tr> via jQuery, So I am using following function
$("#del_yes").click(function() {
$("tr#post_".post).remove();
});
Please note that post is a global javascript variable defined by me, I've tested it by alerting it, And I am getting the expected value of it, which contains the id of a <tr> tag like 1, 2 and html is like <tr id="post_1">, <tr id="post_2"> etc..
So at run time it is supposed to be like $("tr#post_1").remove();, $("tr#post_2").remove(); etc..
I dont know what is getting wrong, I am not able to remove <tr>
Your string concatenation is wrong. Use + instead of ..
$("#del_yes").click(function() {
$("tr#post_" + post).remove();
});
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?
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();
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)
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 3 years ago.
Improve this question
I am trying to manipulate elements outside of iframe by setting JS inside of my iframe
The style.backgroundColor code works but not innerHtml
I have
<script type="text/javascript">
//get main document element.
var ititle= parent.document.getElementById('MainTitle');
//works
ititle.style.backgroundColor = "#FFCC00";
//doesn't work
ititle.innerHtml='test html';
</script>
The above script is inside my iframe
Are there any reasons why? Thanks a lot.
Because JavaScript is CaseSensitive, and it's innerHTML (all uppers):
ititle.innerHtml='test html';
//should be
ititle.innerHTML='test html';