I'm trying to select a wordpress category "Announcement" in a post form automatically using javascript.
When I inspect the input box, here is the code.
<input type="checkbox" id="cred_form_937_1-checkbox-1-1538849482"
name="category[]" data-wpt-type="checkbox" data-wpt-
id="cred_form_937_1_cred_form_937_1-checkbox-1-1538849482" data-wpt-
name="category[]" value="3" data-parent="-1" data-value="Announcement"
class="wpt-form-checkbox form-checkbox checkbox">
I have tried the following, but it does not work.
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-
core/6.1.19/browser.min.js"></script>
<script>
var input = document.getElementById('cred_form_937_1-checkbox-1-
1538849482');
input.focus();
input.select();
jQuery(document).ready(function() {
jQuery( '#cred_form_937_1-checkbox-1-1538849482' ).prop('checked',
true);
});
</script>
Aucun commentaire:
Enregistrer un commentaire