jquery module not working --- need help!
Ok, so I wrote this program: https://codepen.io/justjim1220/pen/dapLPo?editors=1000
And in CodePen, it works perfectly.
But I have attempted to convert it over to be a MagicMirror module:
it shows up exactly as it should, BUT, none of the buttons work.
I get the hover action, and even the click action, but the buttons don’t do anything else.
Plus, I don’t get any errors in dev console.
sdetweil last edited by sdetweil
@justjim1220 we discussed this offline…
the jquery code is executing inline of the getDom() function, and the element selectors
$('#more') is same as (document.getElementById('more'))
will fail as the content is not IN the html document yet
MagicMirror is what is called a Single Page web application. one html page.
the base framework defines the page layout and regions. each module can contribute ITS little piece of content by returning the top element of that content starting with a div.
the getDom module function is responsible for developing and returning that div tree.
sometime AFTER the getdom function returns with the div object
var wrapper= document.createElement('div') return wrapper
the div will be inserted into the dom at the module defined location. (position)
note that multiple modules may contribute to the same location, in a FIFO order. (as defined in config.js)
any code inside getDom() that attempts to locate elements by ID (search the single page dom) will FAIL,
as the modules dom contribution has not been inserted until AFTER sometime getdom() returns the div element
You can’t just go copy something and plug it in… you have to have an understanding of how it works… @sdetweil gave a REALLY great explanation.
You can load your jquery either with the above getScripts or you can do in the getDom … I have a few things working with jQuery… go look at my MMM-Recipe module…for an example of how I did it.
@cowboysdude Thanks! I will do that!
@cowboysdude How do I mark this as SOLVED?
@justjim1220 I’d like to see what you did.
With what you have taught me and with the changes to the Video Player and the Kitchen timer,
I am gonna try to apply this to a few other programs I have ready to convert from JQuery.
I am also going through @cowboysdude’s Recipe module to see how to get JQuery to actually work with MM.
Maybe it will steer me away from JQuery in the future!
I really like the changes you’ve made with this Recipe Module!!!
@justjim1220 yeh, his use of jQuery is not against the HTML as u were doing, but against data items returned from other sources.