Categories
JavaScript Answers

How to remove slide down effect with Twitter Bootstrap modal with CSS?

Sometimes, we want to remove slide down effect with Twitter Bootstrap modal with CSS.

In this article, we’ll look at how to remove slide down effect with Twitter Bootstrap modal with CSS.

How to remove slide down effect with Twitter Bootstrap modal with CSS?

To remove slide down effect with Twitter Bootstrap modal with CSS, we can set the transition and transform styles to none.

For instance, we write

.modal.fade .modal-dialog {
  -moz-transition: none !important;
  -o-transition: none !important;
  -webkit-transition: none !important;
  transition: none !important;

  -moz-transform: none !important;
  -ms-transform: none !important;
  -o-transform: none !important;
  -webkit-transform: none !important;
  transform: none !important;
}

to select the elements with the modal-dialog class in the elements with the modal-fade class and set their transition and transform styles to none for each kind of browser.

We use !important to override the existing styles.

Conclusion

To remove slide down effect with Twitter Bootstrap modal with CSS, we can set the transition and transform styles to none.

Categories
JavaScript Answers

How to detect that the browser has no mouse and is touch-only with JavaScript?

Sometimes, we want to detect that the browser has no mouse and is touch-only with JavaScript.

In this article, we’ll look at how to detect that the browser has no mouse and is touch-only with JavaScript.

How to detect that the browser has no mouse and is touch-only with JavaScript?

To detect that the browser has no mouse and is touch-only with JavaScript, we can detect if the device supports hovering with window.matchMedia.

For instance, we write

if (window.matchMedia("(any-hover: none)").matches) {
  // ...
}

to call window.matchMedia with "(any-hover: none)" to check if the device supports hovering over content with the mouse.

And we use matches to return whether this is true or false.

Conclusion

To detect that the browser has no mouse and is touch-only with JavaScript, we can detect if the device supports hovering with window.matchMedia.

Categories
JavaScript Answers

How to use querySelectorAll with multiple conditions with JavaScript?

Sometimes, we want to use querySelectorAll with multiple conditions with JavaScript.

In this article, we’ll look at how to use querySelectorAll with multiple conditions with JavaScript.

How to use querySelectorAll with multiple conditions with JavaScript?

To use querySelectorAll with multiple conditions with JavaScript, we can call querySelectorAll with all the selectors separated by a comma.

For instance, we write

const list = document.querySelectorAll("form, p, legend");

to select all form, p, and legend elements in the document.

Conclusion

To use querySelectorAll with multiple conditions with JavaScript, we can call querySelectorAll with all the selectors separated by a comma.

Categories
JavaScript Answers

How to split a string at the first / and surrounding part of it in a span with JavaScript?

Sometimes, we want to split a string at the first / and surrounding part of it in a span with JavaScript.

In this article, we’ll look at how to split a string at the first / and surrounding part of it in a span with JavaScript.

How to split a string at the first / and surrounding part of it in a span with JavaScript?

To split a string at the first / and surrounding part of it in a span with JavaScript, we can use the string replace method.

For instance, we write

date.innerHTML = date.innerHTML.replace(/^(..)\//, "<span>$1</span></br>");

to call date.innerHTML.replace with a regex that matches any content before a slash and replace the content with a span element that wraps around the content and add a br element after the span.

Then we assign the returned string back to date.innerHTML to update the content.

Conclusion

To split a string at the first / and surrounding part of it in a span with JavaScript, we can use the string replace method.

Categories
JavaScript Answers

How to append HTML string to the DOM with JavaScript?

Sometimes, we want to append HTML string to the DOM with JavaScript.

In this article, we’ll look at how to append HTML string to the DOM with JavaScript.

How to append HTML string to the DOM with JavaScript?

To append HTML string to the DOM with JavaScript, we can use the insertAdjacentHTML method.

For instance, we write

div.insertAdjacentHTML("beforeend", str);

to call div.insertAdjacentHTML with 'beforeend' and str to append the content of str to the end of the div.

Conclusion

To append HTML string to the DOM with JavaScript, we can use the insertAdjacentHTML method.