What I have with jQuery:
if ($('#vote_c').length > 0) {
$('#vote_button').show().click();
}
I am trying to re-write it so it uses raw javascript:
if (document.getElementById('vote_c').length > 0) {
// what goes here
}
// cache lookup
var vote = document.getElementById('vote_c');
// using truthy/falsy value to determine existence
// proper test would be (vote !== null)
if (vote) {
// this is probably closest to what .show() does
// .show actually seems to track what the initial
// computed display state for the element was and
// along with .hide, toggles between the initial
// state and 'none'.
vote.style.display = '';
// mimicking .click() is done any number of ways
// but the easiest is below:
vote.onclick(); // call any registered handlers for the click event;
//
// OR (second easiest way) you could define a click event:
//
var event = new MouseEvent('click', {
"view": window,
"bubbles": true,
"cancelable": true
});
// and then "dispatch" that event to the targeted
// element which should trigger the handlers
vote.dispatchEvent(event);
}
document.getElementById('vote_c').lengthid is unique, so this function selects only one single element, no need in.length.document.dispatchEvent(event);?