Need help with jQuery

Hey guys,
We are creating a commentbox, but we don’t understand the purpose of including the two codes marked with bold. Can someone tell us in detail about the section below? Would be much appriecated

// We create a comment box.

var _val = $(this).data(“role”),

_sizeValIn = parseInt($(this).data(“size-val”) + 1),

_sizeValRe = parseInt($(this).data(“size-val”) - 1),

_size = $(this).data(“size”);

if(_size == “in-size”){

document.execCommand(_val, false, _sizeValIn + “px”);

} else{

document.execCommand(_val, false, _sizeValRe + “px”);




1 Like

Three things are happening here.

  • $(this).data(“size-val”) gets the data from the element $(this). You will need to console.log to know what is inside here.

  • parseInt() makes sure the data you request is in the form of a interger. This makes sure you can run math on the output without getting errors. Using math on strings can create very unexpected results after all.

  • + 1 here you attempt to add 1 to the value that came out $(this).data(“size-val”) (You might want to put this outside the parseInt() function so you wont get unexpected errors).

1 Like

Great, made great sense. Thank you so much!

Do you know about the final part as well:

document.execCommand(_val, false, _sizeValIn + “px”);

1 Like

No sorry. I haven’t had to use this function yet.

Here is the related documentation tho. It might answer your question.

1 Like