using .prop() with jsdom doesn´t work

27 views
Skip to first unread message

mischu

unread,
Aug 11, 2021, 9:39:17 AM8/11/21
to jsdom
Hello together,
I am using jsdom on my node server. Everything works fine. But I have problems with using the .prop() statement to check or uncheck checkboxes. The .attr() statement is doing well.

.attr works fine:
$('#' + Id).attr(attr, value);

but .prop() doesn´t work:
$('#' + Id).prop('checked', true); 

Would be happy for some help.

Thanks
Michael

Michael Schubert

unread,
Aug 11, 2021, 10:05:14 AM8/11/21
to jsdom
To clarify my post: If prop() is not supported, is there also another way to check or uncheck checkboxes? 
Thanks!

Domenic Denicola

unread,
Aug 11, 2021, 10:41:35 AM8/11/21
to js...@googlegroups.com

Can you post a full code sample using https://npm.runkit.com/jsdom ?

--
You received this message because you are subscribed to the Google Groups "jsdom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsdom+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsdom/9000e6a1-4e55-4446-8161-0975cce606a2n%40googlegroups.com.

Michael Schubert

unread,
Aug 11, 2021, 11:03:42 AM8/11/21
to jsdom
Would be great if we can fix it without a full code sample:

My code is very simple. I have only three variables:
  1.  type to identify the type (button, checkbox, range,...).
  2.  attr (checked, min, max,...) 
  3.  value (100, true, false,...)
I am using only these few rows:

let jsdom = require("jsdom");
let dom = new jsdom.JSDOM(myHtml);
let $ = require("jquery")(dom.window);

 if(type != 'checkbox'){
    $('#' + id).attr(attr, value);
} else {
    $('#' + id).prop(attr, value);
}

attr() works great, but prop() doesn't work... I checked all my variables with a log. 

Variables for prop():
 $(Id_1).prop('checked', true);

Michael Schubert

unread,
Aug 11, 2021, 11:16:18 AM8/11/21
to jsdom
my html code is:

<div class="custom-control custom-switch mt-3 ml-4"> 
    <input type="checkbox" class="custom-control-input" id="id_1">
</div>

Updating the html on the client side works fine. Only on the serverside with .prop() it doesn´t work
Reply all
Reply to author
Forward
0 new messages