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';
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 3 days ago.
Improve this question
When the page loads, I would like to take the actual URL of the page, save it into a variable and then search with jQuery, an element with the same URL of the actual page. If jQuery finds that with the same href, then add a class to that element.
This is what I've actually:
$(function() {
var url = $(location).attr('href');
console.log (url);
$('a[href="${url}"]').addClass( "a-selected" );
});
I'm taking the actual URL correctly. And if I change a[href="${url}] to -> a[href="my-url.com/stacksoverflow"] , the class applies! But when I change to use the $url variable then the class is not appling
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 5 months ago.
Improve this question
This is normal text : I need to change an image element's source using ${} with an entry but it doesn't recognize the $ sign as an directory.so it doesn't load any picture because it simply doesn't find a picture with name of "dice-${dicee}.jpg"
here is the code:
document.getElementsByClassName('btn--roll')[0].addEventListener('click',()=>{
const dicee = Math.trunc(Math.random()*6)+1;
diceElement.classList.remove('hidden');
diceElement.src = 'images/dice-${dicee}.jpg';
})
Interporlation only works inside template literals
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
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>
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 9 years ago.
Improve this question
I'm trying to change the body content when I resize the windows, but after 2 hours searching and trying, I get nothing.
This is my last jQuery code:
$(window).resize(function(){
if($(window).width<=320){
changeHTML();
}
});
var changeHTML=function(){
alert("wow");
//$('body').load('../index2.html');
}
The "index2.html" is something like this:
<div>
A lot of stuff
</div>
$(window).width is incorrect, as width() is a method. Use $(window).width() instead.
See working jsFiddle demo