0

I'm looking for a CSS tag that can provide an id for text. I want to be able to modify the text with javascript, so i need something like:

<texttag id="the_id">the text</texttag>

All the other tags i've tried affect the formatting one way or another. For example it would be used in a sentence, such as:

You live in <texttag id="town_id">Newmarket</texttag>.  Thats a nice town.

And it would display as:

You live in Newmarket. Thats a nice town.

But I would have the ability to modify Newmarket with the id town_id ..

See what i mean? If I use <p> or <div> the text wraps..

1
  • I think you've confused CSS selectors and HTML elements (tags). HTML elements are the things in your web page with angle brackets. A CSS selector is something that goes in your stylesheet, one of which can be a HTML element (ie, a { color:red; } makes all <a> elements red), among other things. More info here. Commented Jul 26, 2010 at 23:40

1 Answer 1

4

The <span> HTML tag has a display of inline and has no presentational nor semantic meaning attached to it. You can use CSS to apply whatever styles you'd like or script to modify the element's contents.

This sentence has <span id="whatever">text</span>.

To change contents:

docuent.getElementById('whatever').innerHTML('changed text');

To style that specific element:

#whatever { font-weight:bold; }

Also, you may want to read about the difference between block and inline elements. (And an expanded explanation here.) (<p> and <div> are block; <span> is inline.)

Sign up to request clarification or add additional context in comments.

Comments

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.