Hi, I know the problem but I don’t know how to fix this. This is JQuery image slider and I used digit as my ID attribute but unfortunately, W3C invalid returns because:
Line 222, Column 18: value of attribute “id” invalid: “1” cannot start a name
In this case, I know that I cannot use digit as my id but the code makes me to use that id… please give me some advice on this thank you
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript">
function Slider(){
$(".slider #1").show("fade", 500);
$(".slider #1").delay(5500).hide("slide", {direction: 'left'}, 500);
var sc = $(".slider img").size();
var count = 2;
setInterval(function (){
$(".slider #"+count).show("slide", {direction: 'right'}, 500);
$(".slider #"+count).delay(5500).hide("slide", {direction: 'left'}, 500);
if(count == sc){
count = 1;
}else{
count = count + 1;
}
}, 6500);
}
</script>
<div class="slider">
<img id="1" src="images/slide0.png" border="0" alt="error" />
<img id="2" src="images/slide1.png" border="0" alt="error" />
</div>
ralphm
May 26, 2012, 12:34pm
2
Hi u4722839. Welcome to the forums.
I know that I cannot use digit as my id but the code makes me to use that id…
Heh heh … Just change the code.
Change the ID in the JS file to anything, such as #one , and then change the HTML too.
Edit:
O, I looked at the code a bit more closely and see what you mean. Maybe try something like:
$(“.slider #s 1”).show(“fade”, 500);
$(“.slider #s 1”).delay(5500).hide(“slide”, {direction: ‘left’}, 500);
…
$(“.slider #s ”+count).show(“slide”, {direction: ‘right’}, 500);
$(“.slider #s ”+count).delay(5500).hide(“slide”, {direction: ‘left’}, 500);
…
<img id=“s 1” src=“images/slide0.png” border=“0” alt=“error” />
<img id=“s 2” src=“images/slide1.png” border=“0” alt=“error” />
Mind you, not validating doesn’t mean it won’t work … although it’s better not to break rules.
Thank you for your reply! I am quite new to JavaScript. Have a nice day
Hi u4722839. Welcome to the forums.
Heh heh … Just change the code.
Change the ID in the JS file to anything, such as #one , and then change the HTML too.
Edit:
O, I looked at the code a bit more closely and see what you mean. Maybe try something like:
$(“.slider #s 1”).show(“fade”, 500);
$(“.slider #s 1”).delay(5500).hide(“slide”, {direction: ‘left’}, 500);
…
$(“.slider #s ”+count).show(“slide”, {direction: ‘right’}, 500);
$(“.slider #s ”+count).delay(5500).hide(“slide”, {direction: ‘left’}, 500);
…
<img id=“s 1” src=“images/slide0.png” border=“0” alt=“error” />
<img id=“s 2” src=“images/slide1.png” border=“0” alt=“error” />
Mind you, not validating doesn’t mean it won’t work … although it’s better not to break rules.
Did it work? I’m no expert with JS, so I may be blowing hot air there.