thomagron thomagron - 1 year ago 100
CSS Question

calling javascript inside a div

here is my code:

$('#next').click(function() {
if ($('.current').hasClass('last')) {
$('#next').attr('disabled', true);
$('#prev').attr('disabled', null);

$('#prev').click(function() {
if ($('.current').hasClass('first')) {
$('#prev').attr('disabled', true);
$('#next').attr('disabled', null);

<script src=""></script>
<!doctype html>
<html lang="en">
<title>javascript problem</title>

<div id='div1' class="first current">
here the content of div 1

<div id='div2'>
here the content of div 2

//then another 9 divs

<div id='div12' class="last">
<input type="submit" value="submit" onclick="submit()">

<div class="buttons">
<button id="prev" disabled="disabled">Prev</button>
<button id="next">Next</button>


what i want to do is have the buttons (in the div 'buttons') in every div and not below. because i want them not to show up at the end, and i want to change the value of it on the first page.
but when i do this, they dont work anymore.

the codesnippet does not work
but what it does is, when you click 'next' the next div will be shown.

here is how i want it:

<div id='div1' class='first current'>
<p>here the content of div 1</p>
<button id="next">Start</button>

hope its clear

Joe Joe
Answer Source

The id attribute in HTML should always be unique. Instead of using the same id on all your next/prev buttons, you should use a class instead. You can then bind the click event using the class instead and it will apply to all the elements with that class.

<button class="next">Start</button>

$('.next').click(function() { ... });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download