innerHTML is changing the value entered [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 2 years ago.
Improve this question
In an app I'm working on, I'd found that updating the DOM by rewriting a new value to innerHTML doesn't give the expected result.
I typed the following command in the DevTools console:
document.querySelector('main-app').shadowRoot.querySelector('.unitslist').innerHTML = '<unit-bar>1</unti-bar><unit-bar>2</unti-bar>'
With the following result:
<unit-bar>1<unit-bar>2</unit-bar></unit-bar>

You have a typo in your strings. You open with <unit-bar>, but close with </unti-bar>. The closing tags are therefore probably ignored by the browser and it guesses where they should be, resulting in the difference you see.

so , you can solve to avoid overwriting: -
1. get the content of the div and that add the current value to update and the existing values
DOMElem.innerHTML = DOMElem.value + (value to be updated)

Related

How do i add attribute to html tag with jQuery [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 1 year ago.
Improve this question
I have a html page with <html> tag where I want to add dir="rtl" and lang="ar" attributes using jQuery when user click on arabic language in drop-down.
I tried using $(html).attr("dir","rtl")
But it returns undefined. Can somebody help as I'm new to jQuery
There is an error on your code, the "html" tag should be written with quotes as folows:
$('html').attr("dir","rtl")
Ok, the question is closed, answer given, so no use for this answer anymore.

Reference-error : Console is not defined of java script i cmd [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 4 years ago.
Improve this question
What should i do ? it is showing reference-error
Don't use capital letter :) Object console defined with lowercase.
console.log('hello')
But I woted to close your question...
You can hit (Ctrl+Shift+i) to inspect the page and see it in the console.
console is a reserved word and it is case sensitive and it must be written in lowercase

Getting an innerHtml text of a tag doesn't work, but innerText is 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 5 years ago.
Improve this question
I'm learning JavaScript and I'm unable to figure out why the below code doesn't return the value inside span tag with id "name".
console.log(document.getElementById('person').innerHtml)
My name is <span id="person">Anon</span>.
incorrect output (returns undefined)
Whereas, replacing innerHtml with innerText works fine.
console.log(document.getElementById('person').innerText)
My name is <span id="person">Anon</span>.
correct output (retuns Anon)
To get the correct result, use .innerHTML with all caps. Sometimes a simple typo can cause your code to become ineffective.

the splice method giving unknown results [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 am trying to check what items are in array.
this is my code
var fruits=['banana','orange','lemon'];
fruits.splice(0,1,'apple');
for (i=0;i<=fruit.length;i++)
{
alert('The fruits are' + fruits[i]);
};
Somehow it's not Working.
please tell me where i am doing wrong.
thanks.
Have you mistakenly added fruit.length or you have written code like this?
syntax;-
array.splice(index,howmany,item1,.....,itemX)
index->positon from/to u want to ad and remove items
howmany->how many item u want add/remove
item->item list(for more than pne seprate it by comma)
also:-
please add s after fruit in for loop

Multiple conditions in 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 9 years ago.
Improve this question
I have created the javascript based demonstration and now I want to hide an image on click in certain condition only.
$("#clear").click(function(){
if ($('#image').is(":visible") && ('#image2').is("hidden")) {
$("#image").hide();
};
});
As you can see my code is not right, so I want to know how to format my code properly. I couldn't find the right way to write multiple conditions in one string. Thanks in advance.
The problem is that you forget to add $ (jQuery) to your second condition and selector hidden is incorrect, should be :hidden:
if ($('#image').is(":visible") && $('#image2').is(":hidden"))

Categories