HTML (HyperText Markup Language) is the principal markup language used for structuring web pages and formatting content. The most recent iteration of HTML is HTML5.

learn more… | top users | synonyms (1)

1330
votes
36answers
703k views

RegEx match open tags except XHTML self-contained tags

I need to match all of these opening tags: <p> <a href="foo"> But not these: <br /> <hr class="foo" /> I came up with this and wanted to make sure I've got it right. I am ...
370
votes
16answers
77k views

What are valid values for the id attribute in HTML?

When creating the id attributes for HTML elements, what rules are there for the value?
23
votes
7answers
8k views

Grabbing the href attribute of an A element

Trying to find the links on a page. my regex is: /<a\s[^>]*href=(\"\'??)([^\"\' >]*?)[^>]*>(.*)<\/a>/ but seems to fail at <a title="this" href="that">what?</a> ...
139
votes
12answers
45k views

Robust and Mature HTML Parser for PHP

Are there any robust and mature HTML parsers available for PHP? A quick skimming of PEAR didn't turn anything up (lots of classes for generating HTML, not so much for consuming), and Google taught me ...
209
votes
10answers
14k views

Can you provide some examples of why it is hard to parse XML and HTML with a regex?

One mistake I see people making over and over again is trying to parse XML or HTML with a regex. Here are a few of the reasons parsing XML and HTML is hard: People want to treat a file as a sequence ...
286
votes
24answers
170k views

Convert HTML + CSS to PDF with PHP?

Ok, I'm now banging my head against a brick wall with this one. I have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in ...
76
votes
6answers
28k views

Regular expression pattern not matching anywhere in string

I am trying to match <input> type “hidden” fields using this pattern: /<input type="hidden" name="([^"]*?)" value="([^"]*?)" />/ This is sample form data: <input type="hidden" ...
355
votes
8answers
32k views

Why don't self-closing script tags work?

What is the reason browsers do not correctly recognize: <script src="foobar.js" /> <!-- self-closing script tag --> Only this is recognized: <script ...
195
votes
2answers
89k views

How to use HTML Agility pack

How do I use the HTML Agility Pack? My XHTML document is not completely valid. That's why I wanted to use it. How do I use it in my project? My project is in C#.
1020
votes
38answers
559k views

Href attribute for JavaScript links: “#” or “javascript:void(0)”?

When building a link that has the sole purpose to run JavaScript code, there are 2 ways to write the code. Which is better, in terms of functionality, page load speed, validation purposes, etc? <a ...
57
votes
0answers
8k views

How to parse HTML with PHP? [duplicate]

Possible Duplicate: How to parse and process HTML with PHP? Suggestion for a reference question. Stack Overflow has dozens of "How to parse HTML" questions coming in every day. However, ...
247
votes
13answers
118k views

Modify the URL without reloading the page

Is there any way I can modify the URL of the current page without reloading the page? I would like to access the portion before the # hash if possible. I only need to change the portion after the ...
90
votes
5answers
15k views

What are the pros and cons of the leading Java HTML parsers?

Searching SO and Google, I've found that there are a few Java HTML parsers which are consistently recommended by various parties. Unfortunately it's hard to find any information on the strengths and ...
246
votes
19answers
40k views

Frame Buster Buster … buster code needed

Let's say you don't want other sites to "frame" your site in an <iframe>: <iframe src="http://example.org"></iframe> So you insert anti-framing, frame busting JavaScript into all ...
221
votes
31answers
135k views

How to detect if JavaScript is disabled?

There was a post this morning asking about how many people disable javascript. Then I began to wonder what techniques might be used to determine if the user has it disabled. Anyone know of some ...
308
votes
16answers
198k views

Using jQuery to center a DIV on the screen

How do I go about setting a <div> in the center of the screen using jQuery?
207
votes
13answers
124k views

jQuery Set Cursor Position in Text Area

How do you set the cursor position in a text field using jQuery? I've got a text field with content, and I want the users cursor to be positioned at a certain offset when they focus on the field. ...
113
votes
0answers
60k views

Looking for C# HTML parser [duplicate]

Possible Duplicate: What is the best way to parse html in C#? I would like to extract the structure of the HTML document - so the tags are more important than the content. Ideally, it ...
25
votes
9answers
133k views

How to get the file path from HTML input form in Firefox 3

We have simple HTML form with <input type="file">, like shown below: <form> <label for="attachment">Attachment:</label> <input type="file" name="attachment" ...
60
votes
17answers
113k views

How to extract img src, title and alt from html using php?

I would like to create a page where all images which reside on my website are listed with title and alternative representation. I already wrote me a little program to find and load all HTML files, ...
161
votes
8answers
16k views

Is it valid to replace http:// with // in a <script src=“http://…”>?

I have the following tag: <script type="text/javascript" src="https://cdn.example.com/js_file.js"></script> In this case the site is HTTPS, but the site may also be just HTTP. (The JS ...
215
votes
22answers
52k views

Determining a web user's time zone

Is there a standard way for a Web Server to determine what time zone offset a user is in? From a HTTP header, or part of the user-agent description perhaps?
306
votes
15answers
106k views

When is a CDATA section necessary within a script tag?

Are CDATA tags ever necessary in script tags and if so when? In other words, when and where is this: <script type="text/javascript"> //<![CDATA[ ...code... //]]> </script> ...
429
votes
17answers
122k views

How do you disable browser Autocomplete on web form field / input tag?

How do you disable Autocomplete in the major browsers for a specific input (or form field)?
95
votes
7answers
72k views

Auto-size dynamic text to fill fixed size container

I need to display user entered text into a fixed size div. What i want is for the font size to be automatically adjusted so that the text fills the box as much as possible. So - If the div is 400px ...
231
votes
13answers
324k views

How to apply CSS to iFrame?

I have simple page that has some iFrame sections (to display RSS links). How can I apply the same CSS format for the main page to the page displayed in the iFrame?
115
votes
17answers
116k views

Removing HTML from a Java String

Is there a good way to remove HTML from a Java string? A simple regex like replaceAll("\\<.*?>","") will work, but things like &amp; wont be converted correctly and non-HTML between ...
265
votes
18answers
311k views

Recommended way to embed PDF in HTML? [closed]

What is the recommended way to embed PDF in HTML? iFrame? Object? Embed? What does Adobe say itself about it? In my case, the PDF is generated on the fly, so it can't be uploaded to a ...
215
votes
23answers
182k views

Auto detect mobile browser (via user-agent?)

How can I detect if a user is viewing my web site from a mobile web browser so that I can then auto detect and display the appropriate version of my web site?
228
votes
39answers
325k views

How to allow only numeric (0-9) in HTML inputbox using jQuery?

I am creating a web page where I have an input text field in which I want to allow only numeric characters like (0,1,2,3,4,5...9) 0-9. How can I do this using jQuery?
101
votes
20answers
108k views

Convert HTML to PDF in .NET [closed]

I want to generate PDF by passing HTML contents to a function. I have made use of ItextSharp for this but it does not perform well when it encounters Table and the layout just gets messy. Is there ...
175
votes
40answers
48k views

Options for HTML scraping?

I'm thinking of trying Beautiful Soup, a Python package for HTML scraping. Are there any other HTML scraping packages I should be looking at? Python is not a requirement, I'm actually interested in ...
133
votes
8answers
236k views

How to send HTTP request in java?

I want to compose a HTTP request message in java and then want to send it to a HTTP WebServer. I also want the document content of the page recieved which I would have recieved if I had sent the same ...
97
votes
20answers
116k views

In JavaScript can I make a “click” event fire programmatically for a file input element?

I'd like to make a click event fire on an <input type="file"> tag programmatically. Just calling click() doesn't seem to do anything or at least it doesn't pop up a file selection dialog. I've ...
63
votes
6answers
25k views

Manipulating CSS :before and :after pseudo-elements using jQuery

Is there any way to select/manipulate CSS pseudo elements using jQuery? Eg, my stylesheet has a rule stating... .span:after{ content:'foo' } How can I change 'foo' to 'bar' using jQuery?
56
votes
9answers
59k views

parsing HTML on the iPhone [closed]

Can anyone recommend a C or Objective-C library for HTML parsing? It needs to handle messy HTML code that won't quite validate. Does such a library exist, or am I better off just trying to use ...
71
votes
13answers
32k views

How do you get the footer to stay at the bottom of a Web page?

I have a simple 2-column layout with a footer that clears both the right and left div in my markup. My problem is that I can't get the footer to stay at the bottom of the page in all browsers. It ...
233
votes
15answers
159k views

Invoking javascript in iframe from parent page

Basically, I have an iframe embedded in a page and the iframe has some javascript routines I need to invoke from the parent page. Now the opposite is quite simple as you only need to call ...
62
votes
3answers
21k views

Why split the <script> tag when writing it with document.write()?

Why do some sites (or advertisers that give clients javascript code) employ a technique of splitting the <script> and/or </script> tags up within document.write() calls? I noticed that ...
123
votes
11answers
40k views

jQuery/Javascript to replace broken images

I have a web page that includes a bunch of images. Sometimes the image isn't available so a broken image is displayed in the clients browser. How do I use jQuery to get the set of images, filter it ...
87
votes
13answers
47k views

What are all the valid self-closing elements in XHTML (as implemented by the major browsers)?

What are all the valid self-closing elements (e.g. <br/>) in XHTML (as implemented by the major browsers)? I know that XHTML technically allows any element to be self-closed, but I'm looking ...
597
votes
16answers
517k views

How to center a div in a div - horizontally?

How do I horizontally center a div in a div with CSS (if it's possible at all)? The outer div has 100%: <div id="outer" style="width:100%"> <div id="inner">Foo foo</div> ...
126
votes
12answers
12k views

Custom attributes - Yea or nay?

Recently I have been reading more and more about people using custom attributes in their HTML tags, mainly for the purpose of embedding some extra bits of data for use in javascript code. I was ...
68
votes
10answers
85k views

Using C# regular expressions to remove HTML tags

How do I use C# regular expression to replace/remove all HTML tags, including the angle brackets? Can someone please help me with the code?
193
votes
15answers
265k views

Stretch and scale CSS background

Is there a way to get a background in CSS to stretch or scale to fill its container?
58
votes
27answers
12k views

Can you provide examples of parsing HTML?

How do you parse HTML with a variety of languages and parsing libraries? When answering: Individual comments will be linked to in answers to questions about how to parse HTML with regexes as a ...
116
votes
11answers
19k views

Is it recommended to use the <base> html tag?

I just found out about the <base> HTML tag. I have never seen it actually used anywhere before. Are there pitfalls to its use that means I should avoid it? The fact that I have never noticed ...
116
votes
16answers
100k views

Strip HTML from Text JavaScript

Is there an easy way to take a string of html in JavaScript and strip out the html?
21
votes
5answers
23k views

Can scripts be inserted with innerHTML?

I tried to load some scripts into a page using innerHTML with a div. It appears that the script loads into the dom, but it is never executed (at least in ff and chrome). Is there a way to have scripts ...
196
votes
2answers
23k views

Why do browsers match CSS selectors from right to left?

CSS Selectors are matched by browser engines from right to left. So they first find the children and then check their parents to see if they match the rest of the parts of the rule. Why is this? Is ...

1 2 3 4 5 279