Is it valid to put h2 tag in span tag? - seo

Is it valid to put h2 tag in span tag given that the span tag is displayed as block?
would it make difference for search engines (SEO) if i used div instead

Sample input:
<!DOCTYPE HTML>
<html>
<head><title></title></head>
<body>
<span style="display: block">
<h2>A</h2>
</span>
</body>
</html>
And results from W3C validator:
Element h2 not allowed as child of element span in this context.

No, you can't. Accordind to HTML 4.01/XHTML 1.0 dtd you can include only inline elements in span tag. It's the following one:
a, object, applet, img, map, iframe, br, span, bdo, tt, i, b, u, s, strike, big, small, font, basefont, sub, sup, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, input, select, textarea, label, button, ins, del, script.
Can't quickly check HTML 5, but don't think it's different here.

In HTML4, it is not valid to put any block element inside of any inline element.
This changes in HTML5, where it is valid to put block-level elements inside of anchor tags.

Related

Could you help me with xpath of a similar html structure?

<div>
<div>
<div>
<h1 >text1<h1>
<div>
<div>
<div>
<div>
<p> some text <p>
I would like to have the XPath for <p>some text<p> which follows <h1>text1<h1>
Depending upon how much you know about the structure, you could make the XPath a bit more specific, and if you need to worry about whitespace decide whether you could use = or should use contains(), or normalize the whitespace with normalize-space() before comparing.
However, first identify the h1 element, and then use the following:: axis to target the p:
//h1[. = "text1"]//following::p[contains(text(), "some text")]
Not totally clear if those divs the OP is showing are on the same level, but when they are and you don't want to be depend on amount of nested div's, you could use:
//div[.//h1[contains(text(),'text1')]]/following-sibling::div//p[contains(.,'some text')]
If you can depend on amount of nested divs then the following XPath wil certainly perform better
//div[div/div/h1[contains(text(),'text1')]]/following-sibling::div/div/div/div/p[contains(.,'some text')]
In case the "some text" is unique you can simply use the following XPath
//p[contains(text(),'some text')]
or
//*[contains(text(),'some text')]
or
//p[text()='some text']
or
//*[text()='some text']
If you want to write Xpath of some text based on text1.
Xpath :
//h1[contains(text(),'text1')]/following-sibling::h1/descendant::p[last()]/preceding-sibling::p
Read more about xpath Axes here
This will be the xpath of the above p tag contains "some text"
//div//div//div//div//p

Get attributes of a empty child node

I want to transform a old HTML4 code to have closed tags in order to achieve compatibility with WCAG.
I have a lot of anchors without content, used as internal links, like
<h3> <a id="julio" name="julio"></a>Julio 2015</h3>
For reasons I do not understand, some browsers do not understand the self-enclosed tag, and interpret it as the start of an anchor (without end).
<h3> <a id="julio" name="julio"/a>Julio 2015</h3>
Then, I want to delete empty anchors and move the attributes to the parent tag:
<h3 id="julio" name="julio">Julio 2015</h3>
The tool I have to use only supports XSLT 1.0
How can I get it?

jQuery selector, IE <P><FORM> selector behavior

If your prepend a FORM element with a P element, elements below the DIV in the example will not be selected!
<P><FORM id=f ...
<INPUT ...>
<DIV><INPUT (this element is not selectable)
</DIV>
</FORM>
No $('#f INPUT').events will happen in IE for the second input above
Try the testcase at: http://jsfiddle.net/jorese/Bzc7M/
In IE you will receive an alert=3, remove the P element in front of the FORM element and you get the expected alert=5. In Chrome|FF you get alert=5 as expected.
Can somebody explain this?
Your HTML code is not valid, it contains a few errors, the reason why some browsers render it is that they tolerate invalid code to some extent by trying to guess what the developer originally wanted to write.
The div element can be used to group almost any elements together. Indeed, it can contain almost any other element, unlike p, which can only contain inline elements.
Use div instead:
http://jsfiddle.net/mshMX/
Sitepoint reference: http://reference.sitepoint.com/html/p
W3 reference http://www.w3.org/TR/html4/sgml/dtd.html
A former StackOverflow question about the same problem: Why <p> tag can't contain <div> tag inside it?

libxml2 get inner (X)HTML

I have some sample XHTML data, like this:
<html>
<head>
<style type="text/css">
..snip
</style>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.js"></script>
</head>
<body>
<div id="contentA">
This is sample content <b> that is bolded as well </b>
</div>
</body>
</html>
Now, what I need to do, is using an xmlNode *, get the inner HTML of the div contentA. I have the xmlNode * for it, but how can I get the innerXML of that? I looked at content, but that only returns This is sample content and not the xml in the bold tags. I looked into jQuery for this, but due to limitations on Apple and JavaScript, I cannot use jQuery to get the innerXML of that node.
On another note, Is there another library I should be using to get the inner XML? I looked into TBXML, but that had the same problem.
The content of the div node is not a single text string. It probably consists of:
A text node containing This is sample content (with the preceding new line).
an element node with a tag name of b
A text node containing the trailing new line and the indentation up to the div's closing tag.
The element node for the <b>...</b> will have the text content that is bolded as well.
To get all the text in the div as one string, you'll need to recursively descend through the entire tree of child nodes looking for text content.

i want append html content into DIV tag

var test ="<html><head><title>JSON Template</title><script type='text/javascript'>widgetbuilder.render({'displayParams':{'wtitle':'Columns','target':'wid1','classlist':{"+result+"},'displimit':'5'},'contentParams':{'channel':'news','category':'columns','wid':'widget1','entity':'Article','limit':'6'}});</script></head><body><div><ul id='wid1'></ul></div></body></html>";
$("#lightbox-panel").append(test);
The tag is nothing more than a container for other tags. Much like the body tag, Div elements are block elements and work behind the scenes grouping other tags together. Use only the following attributes with your div element, anything else should be reserved for CSS
id
width
height
title
style