Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
salezian
Creator
Creator

Qlik extension tutorial question

Dear Qlik Community

I'm trying to build extension using official tutorial. In the first step there's a code to detect if element exists or not.

var id = layout.qInfo.qId + '_helloworld'; 
var $helloWorld = $( '#' + id ); 
if ( !$helloWorld.length ) { console.log( 'No element found with the given Id'); 
 else {  console.log( 'Found an element with the given Id, so just change it' ); }

These piece of code doesn't work. I cannot trace why ... Also why at the end of layout.qInfo.qId is added string '_helloworld' ?

Thanks in advance

M.

3 Replies
ErikWetterberg

Hi Marcin,

What does not work? If you open the browser console, dl you get the messages?

The qId is added to create a unique html Id for the element. Best practice is to avoid using html ids, since they need to be unique, but it you do need one, you can use the qId to make it unique.

Hope this helps

Erik Wetterberg

salezian
Creator
Creator
Author

Hi Erik

In theory according the tutorial these piece of code should detect if element already exists and in case when it doesn't exist to create it. Simply the if condition if !($(layout.qInfo.qId.length)) always is false. I was wondering what's the problem.

BR

M.

ErikWetterberg

Hi,

I assume you are referring to this page: Getting started building visualization extensions ‒ Qlik Sense

The element is created and inserted into the DOM with this piece of code:

$helloWorld = $( document.createElement( 'div' ) );

$helloWorld.attr( 'id', id );

$helloWorld.html( 'Hello World' );

$element.append( $helloWorld );

That's a pretty complicated way to create HTML content, but should work.

BTW the condition in the example is:

var $helloWorld = $( '#' + id );

if ( !$helloWorld.length ) {

If you leave the # out it won't work.

Hope this helps

Erik Wetterberg