homepage Welcome to WebmasterWorld Guest from 23.20.112.161
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
problem with show
IntegrityWebDev




msg:4360128
 6:30 pm on Sep 8, 2011 (gmt 0)

I'm not sure if I have this formed incorrectly or if there is a problem elsewhere. I am rather new to jQuery so this is probably simple:

Here is an HTML snippet:
<div class="showanswersnow"><a href="#">Click here to show the answers now.</a></div>

and here is a jQuery snippet:
$('.showtheanswers').click(function() {
$('.ouranswer').show();
});


But when I click this it doesn't display the .ouranswer div.

In another chunk of code i have a countdown time and when it gets to zero the jQuery executes:
$('.ouranswer').show();
and it works there.

Any thoughts?

 

JAB Creations




msg:4360265
 11:39 pm on Sep 8, 2011 (gmt 0)

The first problem is that you're using a framework which generates a ton of overhead and is completely unreliable by using proprietary methods such as innerHTML (and you won't know it until you reach a certain level which is difficult to achieve if you're using a framework to begin with). Stick to real JavaScript.

Here are a couple functions that I use to change the class of an element and to toggle the class of an element...

- John

Change Class
function change(id,newClass)
{
if (document.getElementById(id)) {document.getElementById(id).className=newClass;}
else if (id) {id.className=newClass;}
else {alert('Error: the id \''+id+'\' was not found or has not yet been imported to the DOM.\n\nNew class intended: '+newClass);}
}

// change('element_id','new_style');
// ||
// var s = document.getElementById('sidebar');
// change(s,'new_style');


Toggle Class
function change_toggle(id,c1,c2)
{
if (document.getElementById(id))
{
if (document.getElementById(id).className==c2) {change(id,c1);}
else {change(id,c2);}
}
else {alert('Error: the id \''+id+'\' was not found or has not yet been imported to the DOM.');}
}

//change_toggle('background_color_div','white','grey');

penders




msg:4360292
 12:28 am on Sep 9, 2011 (gmt 0)

Is the onclick event being assigned to the (correct) element? If you put an alert('Hello World') inside the event, does it alert? Is there some confusion over the inner anchor? Should the click event not be applied to this anchor, rather than the outer DIV? Since I guess the anchor is for the benefit of keyboard users?

ctoz




msg:4360476
 12:27 pm on Sep 9, 2011 (gmt 0)

<div class="showanswersnow">
and
$('.showtheanswers')
don't match.

penders




msg:4360507
 1:51 pm on Sep 9, 2011 (gmt 0)

@ctoz: Eyes of a hawk! :)

IntegrityWebDev




msg:4360513
 2:02 pm on Sep 9, 2011 (gmt 0)

Thanks for your help. Turns out the section I needed this for was done away with on the site so it is no longer needed.

ctoz




msg:4360795
 6:51 am on Sep 10, 2011 (gmt 0)

" a framework which generates a ton of overhead and is completely unreliable"


The overhead pain's more or less done with after the first load: and you can organise your code so that the viewer has content to look at/read while the library's loading. I'm a slow learner, not too interested in bells'n'whistles, but I've found jQuery's ajax functions and its callbacks—which allow for precise timing and sequencing—really easy to implement. For me, it was either jQ or some other library, or having to learn Flash, and Flash looked like a more closed system than jQ...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved