Javascript Change Child node visibility to hidden in an ul - javascript

I have the following structure:
It looks like this:
I want to know how one can remove or hide "Test1" from there.
I tried using
document.getElementsByClassName('ms-core-suiteLinkList')[0].childNodes[0].style.visibility='hidden'
but it doesn't work because it says: "Uncaught TypeError: Cannot read property 'childNodes' of undefined.
Using
jQuery(".ms-core-suiteLink")[0].remove();
didn't work either.
Any help is appreciated!

You could try either
document.getElementsByClassName('ms-core-suiteLink-a')[0].style.display = 'none';
or
document.getElementsByClassName('ms-core-suiteLink-a')[0].style.visibility = "hidden";
They should do the job.

Related

how to fix Uncaught TypeError: Can't read property 'addEventListener' of null

in this question I want when I click the button with id="easy", the array is to be displayed in a 9X9 table its a sudoku initial structure plz help
Hello Ruchika,
You have a button with an id 'easy'.You can simply get this button in your javascript code with the help of document.getElementById method,then store it in some variable and then apply the addEventListener to the variable .
Say you want to use a 'click' event on the button,you can do so easily like this:
const btnEasy = document.getElementById('easy');
btnEasy.addEventListener('click',function(){
//your function code here
})

What is the problem with my Uncaught TypeError: Cannot set property 'src' of null

I have trying to change my code with .setAttribute too, the same thing appear..
In Javascript
document.getElementById("MyImg").src = "./sea.jpg";
In HTML :
<img src="./earth.jpg" id="MyImg">
Thank you for any futer answer !
Uncaught TypeError: Cannot set property 'src' of null
The null is the important part. Your DOM search (getElementById) failed.
Some ideas off the top of my head:
The script is running in a different page
The tag is not actually there
There is a misspelling in the id (looks good in your example though)
If you need an example to work off of: https://www.w3schools.com/jsref/prop_img_src.asp

Uncaught ReferenceError: hide is not defined error

I'm newbie on javascript. I'm using Twitter Bootstrap Modal.
console get me this error. why?
Uncaught ReferenceError: hide is not defined
JS
$('#te').modal(hide)
You may try this (Check the documentation):
$('#te').modal('hide');
Notice the quotes, you missed those, hide should be 'hide'.
You need to put quotes around hide.
Like this:
$('#te').modal('hide')
Reference: http://getbootstrap.com/javascript/#modals-usage

Error occurs when i set connectToSortable inside the drag function

I am trying to drag an object and then connect it to 1 of 4 sortable divs. The issue is that since i dont know what the div is, i wrote a script that will, in the drag check to see if the item is in the bounds of a valid option. When it is, it sets the connectToSortable accordingly, but then it crashes.
It when it sets $(this).draggable("option", "connectToSortable", "#"+$(tar).attr("id")); it fails. I was thinking that somehow the draggable object was destroyed, but the big issue is that i cant see where it is broken. The Console is giving me solid logic.
http://jsfiddle.net/mjYt2/
has my example where an error says:
Uncaught TypeError: Cannot read property 'length' of undefined
Maybe i am just doing this horrendously wrong? My goal is to drag an object into a lsit of sortablables. So it will go into the first div, and sort around with "hello" and "World" or it will go to the second and sort about that "hello" and "world".
EDIT: It seems that in my example, the error does not occur if i comment out the inline code as stated above. Something errors there causing the "length" of undefined.
The answer is:
If you assign all the items a class that are sortable, you can then just say:
$(item).draggable({
helper:'clone',
connectToSortable:'.comma,.delimited,#list,#of > .selectors'
});
it seems that i was overthinking it.

JavaScript setting pointer-events

I am trying to set pointer-events: none for a div through JavaScript, however the property is not being applied.
I have tried:
document.getElementById("div").setAttribute("pointer-events", "none");
And:
document.getElementById("div").style.pointer-events = "none";
But neither worked, any ideas?
Your first attempt failed because it was a CSS property and not an attribute (part of the style attribute).
Your second attempt failed because for some off reason, when making this API casing-like-this gets converted to camelCasingLikeThis . This is likely because the folks who built JavaScript and the folks who built CSS weren't very well coordinated.
The following should work:
document.getElementById("div").style.pointerEvents = "none";
You can access style properties via Bracket notation like this:
document.getElementById("div").style['pointer-events'] = 'auto';
No need in camel case modification in this case.
There is an example in a book which uses element.setAttributeNS(null, "pointer-events", "none"); instead of using element.style.pointer-events = "none";.

Categories

Resources