News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

jQuery DIVs?

Started by colby2152, November 06, 2014, 08:42:13 PM

Previous topic - Next topic

colby2152

I am having a tough time with jQuery in SMF.  I don't think I am doing it right.  All I really want to do is having multiple DIVs that are linked to a selection button that hides or shows them.  Ultimately, I only want to have one DIV show at a time, but I am trying to start from scratch.

An example with three images or text links, each connected to its own DIV.  Clicking the image or text link will show the DIV.  Clicking another such image or text link will hide the current DIV and show the new DIV.
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

Herman's Mixen

Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

colby2152

Quote from: The Burglar! on November 06, 2014, 11:01:23 PM
see http://www.w3schools.com/jquery/jquery_hide_show.asp for just an example for hide / show text

I was using that page as a reference.  That is focused on <p> sections of code rather than DIVs.  I also want to adapt the code to handle multiple DIVs.  Any ideas?
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

Suki

Use an on() method on the select:


$('#div1', '#div2', '#div3').hide();
$('#select_ID').on( "change", function() {
    var $this = $(this);
    var div = $this.val();

    // Hide whatever div
    $('#mainDIV').children().fadeOut( "slow", function() {
         // Show the current selected div.
       $('#' + div).fadeIn();
  });

});


This is just some random code, it depends on your HTML structure having a parent div that will hold all your divs and it also depends on each div having an ID with the exact value you are using on your select field:


<select id="select_ID">
  <option value="div1">div 1</option>
  <option value="div2">div 2</option>
  <option value="div3">div 3</option>
</select>



Your html should look like this:

<div id="mainDIV">
    <div id="vessel"></div>
    <div id="div1">div1</div>
    <div id="div2">div2</div>
    <div id="div3">div3</div>
</div>


Dunno, something like that.Heres the jsfiddle for it: http://jsfiddle.net/ygrarto8/

Has some quirks but could serve as a start.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

colby2152

I think I have it working, but it isn't resolving correctly mid-way through the DIVs.  Demo page = http://www.profsl.com/smf/index.php?page=portal

The links work fine until the 'Columns & Articles' link.  You can scroll down and see that all of a sudden the right-hand SimplePortal blocks show (don't show on other DIVs because of some error) within the table.  Furthermore, one of those links is being cut-off, but the code looks fine when I read through it.  Something's off alignment?
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

Suki

There is no event associated with the Columns & Articles, link or any other link after that.

If you have that many links, it would be better to group them into an array or an object with a link => div relationship and use jQuery each() to add an event to all of them, makes it easier for you to keep on adding more.

You can also group all your links inside a div and let jquery to find all anchors inside that particular div, and add an event to them.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

colby2152

Quote from: Suki on November 10, 2014, 08:29:45 AM
There is no event associated with the Columns & Articles, link or any other link after that.

If you have that many links, it would be better to group them into an array or an object with a link => div relationship and use jQuery each() to add an event to all of them, makes it easier for you to keep on adding more.

You can also group all your links inside a div and let jquery to find all anchors inside that particular div, and add an event to them.

Interesting.  It seems to be an issue when I go back into the page, SimplePortal only saves pages up to 48,569 characters, and my DIV/link setup has so much more.
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

Suki

You can always move your JS code to an external  JS file  or go the way I suggest to avoid redundancy code.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

colby2152

Quote from: Suki on November 11, 2014, 07:59:24 AM
You can always move your JS code to an external  JS file  or go the way I suggest to avoid redundancy code.

I had a 50,000 character limit on posts.  I removed that, but that hasn't solved this issue.  The code that is saved keeps on getting cutoff within the Columns & Articles DIV.

Moving the JS code to an external file won't save much space.  The DIVs and all of the links take up a lot of characters.  I am going to try and implement an SSI mechanism to move most of this outside SMF.
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

colby2152

Now my issue comes into play when using a PHP page within SimplePortal.

<?php
include('/smf/portaldemo.php');

?>
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

margarett

Is that path correct? Does your filesystem tree starts directly at the root?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

colby2152

Quote from: margarett on November 12, 2014, 09:16:14 AM
Is that path correct? Does your filesystem tree starts directly at the root?

That worked.  Thanks margarett!

I simply needed to add the full path of /home/profsl/public_html/
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

Matthew K.

Quote from: Suki on November 10, 2014, 08:29:45 AM
There is no event associated with the Columns & Articles, link or any other link after that.

If you have that many links, it would be better to group them into an array or an object with a link => div relationship and use jQuery each() to add an event to all of them, makes it easier for you to keep on adding more.

You can also group all your links inside a div and let jquery to find all anchors inside that particular div, and add an event to them.
Just as a side note, knowing that this is now "working", I would really suggest doing something like Suki or I suggested and not be so redundant with the jQuery.

Advertisement: