Day: January 23, 2018

Show Content if class attribute exists in page.

If you want to show content when class exit in this page then you can use this code .It will give alert ok when class attribute exit in this page , you can change also class to id if you want.

<body>
<div class="home-container">
    <div class="home">

        Content

    </div>
    <span style="cursor: pointer; background: #0f192a;color: #00BD9B" onclick="test()">Click</span>
</div>
</body>

then this is javascript code which give alert if class attribute exit in this page

function test() {
        if (document.querySelector('.home') !== null) {
            alert('ok');
        } else {
            alert('not');
        }
    }

In this code home attribute exit so it will give alert ok.
If you find any problem then please inform me.

Comment

Get selected text or image from ck editor

In ck editor need sometime get selected text or image to process . This is sometime problem in normal code, but i hope this code help you which give you selected text or image . This is simple code which give you which text is select in ckeditor.

var selection = CKEDITOR.instances['content'].getSelection();
if (selection.getType() == CKEDITOR.SELECTION_ELEMENT) {
var selectedContent = selection.getSelectedElement().$.outerHTML;
} else if (selection.getType() == CKEDITOR.SELECTION_TEXT) {
if (CKEDITOR.env.ie) {
selection.unlock(true);
selectedContent = selection.getNative().createRange().text;
} else {
  selectedContent = selection.getNative();
  console.log("The selectedContent is: " + selectedContent);
 }
}

This code give you which text you select in ck editor . If you face any problem then please inform me.

Comment

How to get the ‘height’ and ‘width’ of the screen using jquery?

If you want to show the screen height and width then you can use jQuery. You can aslo get giv height , width using this same process. This is simple code.

var height = $(window).height(); // for height of the browser view
var height = $(document).height(); // for height of HTML document
var width = $(window).width(); // for width of browser view
var width = $(document).width(); // for width of HTML document

If you want to know the screen width, height then this code help you

var height = screen.height;
var width = screen.width;

If you face any problem then please inform me. I will try to help you.

Comment