HTML div id - Mendix Forum

HTML div id

0

Hi, 

I want to affect a div with javascript but the div i want to get in js haven't Id.

I try getElementsByClassName but doesn't work... How can i add an id on my html div ? 

Regards

asked
6 answers
4

Dear Dylan.

It is strongly discouraged to manipulate the DOM via JavaScript. It might work with the current version of Mendix, though you will get trouble in the future platform upgrades, where the core widget are rendered with React. The React rendering, might be done several times it the widget live cycle, and the dom changes will not persist.

What is the function requirement what you would like to implement? Maybe there are better ways.

Cheers, Andries

answered
0
$('.ap_togglemenu').click(function() {
        $(".ap_layout-flex_menu").toggleClass("ap_open");
});

$('.ap_layout-flex_menu a').click(function() {
        $(".ap_layout-flex_menu").removeClass("ap_open");
});

 

this is the javascript code we use to open and close our menu.

answered
0

I just want to collapse a region-sidebar when the user click out this region. I already try this a getElementsByClassName but JS didn't find any element by this way. 

My actual solution for collapse a region-sidebar is a JS trigger a toggle button. This togglebutton have also a custom attribut to check if my region-sidebar is collapse or not.
 But i'm not satisfied by this method.

answered
0

I agree with Andries,
But like he said, what is it that your would like to do with the dom?
for the most common situations there are workarounds and widgets.

 

cheers

answered
0

An example using Dojo/Query to get a HTML nodeList using the class "myClass":

require(["dojo/query"],
function(query){
  var q = query(".myClass");
  console.info(q);
});

 

answered
0

It's not an ID, but you can add class names to elements in the Mendix Modeller. You could then use getElementsByClassName to target the element by class name in JavaScript.

answered