Problem with .each() and coloring labels...
Hello,
I am having a problem a jQuery function I am working on. I want the function to scan all the inputs on a page, and if any are checked, set the corresponding labels bold.
Also here's my code pasted directly:
- <!DOCTYPE HTML>
- <html lang="en-US">
- <head>
- <meta charset="UTF-8">
- <title></title>
- <script type="text/javascript" src="http://www.aurorafxstudios.com/_global/includes/jQuery/jquery-1.5.1.min.js"></script>
- <script type="text/javascript">
- function setStyles() {
- $("input:checked").each(function(i) {
- inputId = $(this).attr("id");
- $('label[for="'+inputId+'"]').style.fontWeight="bold";
- });
- }
- $(document).ready(function(){
- $("#test5").attr('checked', true);
- setStyles();
- });
- </script>
- </head>
- <body>
- <form>
- <input id="test1" type="checkbox" checked="checked"><label for="test1">Test 1</label><br>
- <input id="test2" type="checkbox"><label for="test2">Test 2</label><br>
- <input id="test3" type="checkbox" checked="checked"><label for="test3">Test 3</label><br>
- <input id="test4" type="checkbox"><label for="test4">Test 4</label><br>
- <label for="test5">Test 5</label><input id="test5" type="checkbox"><br>
- <label for="test6">Test 6</label><input id="test6" type="checkbox"><br>
- </form>
- </body>
- </html>
Anyone have any advice as to what I am doing wrong?
Thank you!
Jesse