Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Quick Javascript/CSS Question

Name: Anonymous 2011-05-13 19:41

Howdy, /prog/. Is this place still somewhat good, or did the true /prague/riders get  overrun by skiddie /g/ kids? I mean, more than usual.

My ``serious'' programming experience is limited to silly games I write in Sepples with SDL to amuse myself. However, I still believe that I command a decent knowledge of programming and electronics-related topics. One topic I don't know very much about, however, is ``web development'', apart from what I remember from making stupid web pages on Angelfire as an adolescent. So, basically, I want to know whether something is possible with Javascript.

I want to make a ``bookmarklet'' that uses a few lines of Javascript to insert a CSS rule that sets a width to the body div. Did I say that right? I guess I would use document.write to do this, but I don't know what Javascript is allowed to do in a browser (I've never written a single line of it), so I'm not sure. Is this a feasible thing for one to do?

The idea is that, if you're on one of those sites with text that spans the width of the window, and don't feel like resizing your browser, you can just click the bookmarklet, and the entire page will be stuffed into a nice, legible column of text. If I was going to be browsing a site like this for a long period of time, it would make more sense to slap together a custom CSS file for it, but when you just want to look a single page, this would do the trick quite nicely.

Name: ᴍʀ. ᴠɪʟᴇ !PRoGN.piPE 2011-05-13 20:20

Name: Anonymous 2011-05-13 20:20

Sepples with SDL
Sepples on a Saddle.

Name: ᴍʀ. ᴠɪʟᴇ !PRoGN.piPE 2011-05-13 20:21

>>1
double posting here, I didn't check that url before I posted it, but it **used** to be a bookmarklet that did pretty much what you said

Name: Anonymous 2011-05-13 20:50

>>1
I have no experience with webdev either, but you should try to play with the DOM[1][2][3] (which is something awful), document.write is generally a bad idea.

[1] http://en.wikipedia.org/wiki/Document_Object_Model
[2] http://www.w3.org/DOM/
[3] http://www.w3.org/TR/#tr_DOM

Name: Anonymous 2011-05-13 20:53

>>1
not only is it feasible it's actually pretty easy (with the help of a javascript library)

take this jquery code for example:


$("div#mydiv").width("100px");


[url]http://api.jquery.com/width/[/url]

Name: Anonymous 2011-05-13 22:00

>>6
It's also simple without, just a bit longer.
document.getElementByID("#mydiv").style.width = "100px";

Name: Anonymous 2011-05-14 0:25

>>7
Forgive me of my ignorance, for I've only done XML/DOM code for less enlightened languages, but...

getElementByID should return an array or a list of all #mydiv elements. How can you call .style on that? Should't you go through all the elements with a for loop and call .style on them  individually?

Name: Anonymous 2011-05-14 0:58

getElementByID is unique ID, you can't reuse ID

Name: Anonymous 2011-05-14 1:03

MORE LIKE
OP IS TYPICAL JAVASCRIPT PROGRAMMER AND THE DRIVING FORCE BEHIND SHITTY WEB 2.0 APPS
AMIRITE LOLLLLLLLLLLLLLLLLLLLLLLLZzz!!11oNE!!1ONE1!

Name: Anonymous 2011-05-14 10:11

>>8
An ID is a unique identifier. You're probably thinking of getElementsByClass or something. Also you don't need the # in the argument for >>7 , my bad.
Use jQuery anyway though, it lets you do things like $("div.divclass").width("100px"); without having to loop. It may feel a bit heavy, but it's certainly better than >>7.

Don't change these.
Name: Email:
Entire Thread Thread List