document.getElementById()

Status
Not open for further replies.

Malyk

Ars Tribunus Angusticlavius
8,558
Subscriptor
paulr7":aqy17you said:
Malyk":aqy17you said:
have you considered using jQuery?

Mike


jQuery is such a strange paradigm that I think the problem you are trying to solve really has to fit into it before I would commit to actually learning it.


Really?

$("#<id>").hide(500);

Is that different from

document.getElementById(<id>);

and writing all the animation stuff yourself?

Mike
 
I figured out a workaround. I'm passing the unique id name as a variable to the function. Rather than try and figure out an ID that exists but it can't get, this works. I can set the id programatically using php too.

:scared:

I have a feeling you should post a little more of your code and what exactly you're trying to do before you keep on jamming away. Based on your posts, I think you might need some help with some javascript/DOM before reinventing the wheel. ++ on Jquery.
 
pilotlight":3msqho19 said:
I figured out a workaround. I'm passing the unique id name as a variable to the function. Rather than try and figure out an ID that exists but it can't get, this works. I can set the id programatically using php too.

:scared:

I have a feeling you should post a little more of your code and what exactly you're trying to do before you keep on jamming away. Based on your posts, I think you might need some help with some javascript/DOM before reinventing the wheel. ++ on Jquery.

I have a show/hide "link" with an incrementing programmatically created ID for 1 to N items that runs the same function. I'm grabbing the ID from the onclick event, adding a character to it and using this variable to do display:block/display:none a piece of text right below the appropriate link (i.e. clicking on A1 will affect A1-1, A2 will affect A2-1, etc)

Passing it the id name as a variable to the function rather than grabbing the ID of the html element works great. Doing it the other way didn't work in Firefox.
 
Since JQuery was invoked, I'm contractually obligated to mention MooTools. A quick solution:

JS:
Code:
var mycontent = $$('#showmecontent div');
mycontent.hide();
$$('#showmelinks a').addEvent('click', function(e){
   e.stop();
    var x = e.target.get('id');
    var y = x[6];
   mycontent.filter('#showMe'+y).toggle();
});

HTML:
Code:
<div id="showmelinks">
    <a href="#" id="showme1link">show me 1!</a>,
    <a href="#" id="showme2link">show me 2!</a>,
    <a href="#" id="showme3link">show me 3!</a>
</div>
<div id="showmecontent">
    <div id="showMe1">showMe1</div>
    <div id="showMe2">showMe2</div>
    <div id="showMe3">showMe3</div>
</div>

Mooshell:
http://mootools.net/shell/tfcYB/
 

karmakaze

Ars Tribunus Militum
1,700
Subscriptor
Another ++ for jQuery. I didn't think I'd like it at first, but after spending a couple weeks on and off with it on a side project it's really nice.

Especially if you are manipulating css styles. Your code will be much less brittle if you use a lib that handles all that for you.

MooTools might be nice, but I started with Dojo, and switched to jQuery, since it seems to be the lingua franca for client-side scripting at the moment.
 
Status
Not open for further replies.