I've found an answer to a previous question about javascript short hand for this https://stackoverflow.com/a/6398848/1406888 but it is not working for me. I don't understand it because when I use the same short hand in the firefox developer's console it works.
Here's a short example of the code I'm using
<div id="list1">
<li>pres</li>
<li>mike</li>
<li>camel</li>
<li>week</li>
</div>
<p></p>
<div id="list2">
<li>time</li>
<li class="test">era</li>
<li>people</li>
<li>life</li>
</div>
<p></p>
<div id="list3">
<li>time</li>
<li class="test">era</li>
<li>people</li>
<li>life</li>
</div>
<script type="text/javascript">
var testId = document.getElementById("list1");
testId.style.borderStyle="solid";
$("#list2").style.borderStyle="solid";
$("list3").style.borderStyle="solid";
</script>
The only one that works is the list1 border. The other ones fail. Can somebody please correct me.
I now have a working template. Here is my code:
<div id="list1">
<li>pres</li>
<li>mike</li>
<li>camel</li>
<li>week</li>
</div>
<p></p>
<div id="list2">
<li>time</li>
<li class="test">era</li>
<li>people</li>
<li>life</li>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var testId = document.getElementById("list1");
testId.style.borderStyle="solid";
//$("#list2").style.borderStyle="solid"; this does not work
$("#list2").css("border-Style","solid"); this works.
</script>
Just so I get this straight. There is not substitute for getElementById??? I thought it was an interchangable short-hand, but in my example it only works with the .css property of the JQuery shorthand.