/    Sign up×
Community /Pin to ProfileBookmark

Changing p class css with Javascript.

Hi

I’m currently trying to change a css property of a p tag with the class “help”. This is my short and simple code I tried with:

[CODE] var pTags = document.getElementsByTagName(“p”);
pTags.style.width = “280px”;[/CODE]

However, FireBug gives the error “pTags has no properties”. I’m not sure what is wrong, though I can guess. Don’t I need a reference to the class, rather than the p itself? How do I go about doing that?

Would appreciate any help! ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Banana_AnandaJul 26.2007 — Firstly, [B]pTags [/B]is a collection. You'd need to loop through it to change the individual style properties of each element it contains.

If you want to build an array based on class, then a custom function for this will help. There are many around these days.

Take your pick

Good luck
Copy linkTweet thisAlerts:
@LynxoauthorJul 26.2007 — Firstly, [B]pTags [/B]is a collection. You'd need to loop through it to change the individual style properties of each element it contains.

If you want to build an array based on class, then a custom function for this will help. There are many around these days.

Take your pick

Good luck[/QUOTE]

Thanks, looping through the pTags array was the answer. I kinda know what the problem was, but wasn't sure what to do to solve it.
×

Success!

Help @Lynxo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...