<span>
<label for="305">
<input type="checkbox" name="305" style="vertical-align: middle;" value="305" id="305"> Farming General
</label>
</span>
How do I get text “Farming General” using jQuery. Please do not ask me to change HTML structure
You can grab it using an ID selector, going to the
.parent()and using.text()like this:Though, IDs starting with a number aren’t valid until HTML5, just be aware 🙂
You can also get it without jQuery, like this:
Though you may want to trim it down with
$.trim(), like this: