0

I have some basic jquery that is changing the content of a single div. The only thing that I can't figure out is how to show one of the four external HTML files (ie. lookbook20141217.HTML) as the default when the page first loads. Right now, the container DIV "lookBookWindow" is empty until one of the "buttons" is clicked.

JSFIDDLE

HTML

<div id="lookBookMain">

<div id="lookBookWindow"></div>

<input id="lookbook20141217" class="thumbnail rm" type="image" src="thumbnails/20141217.jpg" alt="maurices lookbook20141217" width="220" height="220" border="0" />
<input id="lookbook20141114" class="thumbnail rm" type="image" src="thumbnails/20141114.jpg" alt="maurices lookbook20141114" width="220" height="220" border="0" />
<input id="lookbook20141018" class="thumbnail rm" type="image" src="thumbnails/20141018.jpg" alt="maurices lookbook20141018" width="220" height="220" border="0" />
<input id="lookbook20141016" class="thumbnail" type="image" src="thumbnails/20141016.jpg" alt="maurices lookbook20141016" width="220" height="220" border="0" />

</div>

CSS

#lookBookMain {
    width: 940px;
    margin: 0px auto;
    padding: 0px;
    position: relative;
}

#lookBookWindow {
    width: 940px;
    height: 580px;
    margin: 0px;
    padding: 0px;
}

.thumbnail {
    width: 220px;
    height: 220px;
    margin: 0px;
    padding: 20px 0px 0px 0px;
    position: relative;
    float: left;
}

input.thumbnail:focus {
    outline-width: 0;
}

.rm{
    margin-right: 20px;
}

JQUERY

$('input[type="image"]').click(function() {
    var pageName = this.id;
    $('#lookBookWindow').load(pageName + '.html');
});

I feel like it should just be another line in the jquery, but I'm not finding what I need online. Thanks in advance!

2 Answers 2

2

If you want a specific page to load, just .load() it outside the click handler.

Another option would be to trigger a click on the first image:

$('input[type="image"]').click(function() {
    var pageName = this.id;
    $('#lookBookWindow').load(pageName + '.html');

}).first().click();
Sign up to request clarification or add additional context in comments.

4 Comments

It looks like this option would be a bit more dynamic in that it would always trigger the first "button" regardless if buttons are added/removed/rearranged. If I'm understanding correctly, this would mean I wouldn't have to adjust the jquery when adding buttons and HTML files for the container DIV... right?
That's correct. On the topic of future-proofing, I would suggest giving these inputs a common class and using that in your selector. Currently, if you add an image input that shouldn't be included in this logic, you'll have issues.
Thanks for the tip. I already have a common class of "thumbnail" on the "inputs", so I just added that class to the selector: $('input[type="image"], .thumbnail') Of course, feel free to let me know if I did it wrong.
That selector will select elements that match input[type="image"], and also elements that match .thumbnail. You want $('input[type="image"].thumbnail') or simply $('.thumbnail') might work.
0

I feel like it should just be another line in the jquery

It is. Outside of:

$('input[type="image"]').click(function() {
    var pageName = this.id;
    $('#lookBookWindow').load(pageName + '.html');
});

Add:

$('#lookBookWindow').load('lookbook20141217.html');

Using whichever HTML file you want to load in first.

1 Comment

Yup, that's what I was missing. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.