RE: Help me with my new website!
January 9, 2018 at 12:38 pm
(This post was last modified: January 9, 2018 at 12:47 pm by bennyboy.)
That's definitely a lot more readable and nicer looking.
If you Inspect the page that this puts out (I use Chrome's built-in stuff cuz it's easy), then you'll see that every div has an identical function. if you have a dozen divs, multiplying that short function won't really matter too much. If you have a hundred, it might.
Since you are already assigning the class name "rijecUDrugomDijelu" to every div, then I really think it would be better to write an onclick event for that class, separate from this routine, than to have your routine inject a new instance of the onclick even for every single div you make. Your onclick handler will have to figure out which div called it (which your way doesn't have to do) and then figure out what it's switching with, but overall, it will be a more elegant solution.
Using JQuery (just need to reference a script, it's very easy):
This will give you the id of the clicked div. Then you can go ahead and switch it with another div.
If you Inspect the page that this puts out (I use Chrome's built-in stuff cuz it's easy), then you'll see that every div has an identical function. if you have a dozen divs, multiplying that short function won't really matter too much. If you have a hundred, it might.
Since you are already assigning the class name "rijecUDrugomDijelu" to every div, then I really think it would be better to write an onclick event for that class, separate from this routine, than to have your routine inject a new instance of the onclick even for every single div you make. Your onclick handler will have to figure out which div called it (which your way doesn't have to do) and then figure out what it's switching with, but overall, it will be a more elegant solution.
Using JQuery (just need to reference a script, it's very easy):
Code:
$(".rijecUDrugomDijelu").click(function (event) { // put this in your main script body, not in the div-making routine.
var clickedID = event.target.id; // can also use $(this) to refer to the div
alert(clickedID );
// now do stuff with the div
});
This will give you the id of the clicked div. Then you can go ahead and switch it with another div.