Reputation: 13
I need to get the content of specific tag in HTML as a string or as XML
<body>
<script src="jquery.min.js">
//var test = document.getElementsByTagName("input");
//alert(test[0]);
$(document).ready(function () {
var test = $("input");
alert(test);
}
</script>
<input id="Button1" type="button" value="button" />
<textarea id="TextArea1" rows="2" cols="20"></textarea>
<textarea id="TextArea1" rows="2" cols="20"></textarea>
<input id="Text1" type="text" />
<input id="Text1" type="text" />
<input id="Text1" type="text" />
<circuit>
<c type="Bipolar" name="c1">
<cathode row="10" col="20" />
<anode row="15" col="50" />
</c>
<and name="and1">
``
<input>
<pin row="10" col="40"></pin>
<pin row="20" col="40"></pin>
</Input>
<output>
<pin row="30" col="50"></pin>
</output>
</and>
<diode name="d1" value="30">
<anode row="30" col="50"></anode>
<cathode row="40" col="60"></cathode>
</diode>
<r type="Constant" name="r1">
<node row="60" col="80"></node>
<node row="70" col="80"></node>
</r>
</circuit>
<input id="Text1" type="text" />
<textarea id="TextArea1" rows="2" cols="20"></textarea>
</body>
I need only <Circuit>
tag and all elements inside it like this
<Circuit>
<C Type="Bipolar" Name="c1">
<Cathode row="10" col="20"/>
<Anode row="15" col="50"/>
</C>
<AND Name="and1">``
<Input>
<Pin row="10" col="40"></Pin>
<Pin row="20" col="40"></Pin>
</Input>
<Output>
<Pin row="30" col="50"></Pin>
</Output>
</AND>
<Diode Name="d1" Value="30">
<Anode row="30" col="50"></Anode>
<Cathode row="40" col="60"></Cathode>
</Diode>
<R Type="Constant" Name="r1">
<Node row="60" col="80"></Node>
<Node row="70" col="80"></Node>
</R>
</Circuit>
I'm trying to get this tag by using JQuery, DOM but can't
<script src="jquery.min.js">
$(Document).ready(function ()
{
var test = $("circuit").children(0).html;
alert(test);
}
);
</script>
Also Dom :
var test = document.getElementsByTagName("circuit")
We can't put circuit tag in div
and give div
id , class name , and also circuit tag.
Is there another solution?
Upvotes: 0
Views: 1798
Reputation: 877
I think I got what you want.
1) If you need the "circuit" tags included, then there's no other way other than virtually prepend a tag and get from that, like this Fiddle
$(document).ready(function () {
var test = $("<div>").prepend($("circuit"));
alert(test.html());
});
2) If you don't need the "Circuit" tags, just run like the other answers:
$(document).ready(function () {
var test = $("circuit"));
alert(test.html());
});
Upvotes: 2
Reputation: 8231
You can't write script tags like this. It makes no sense.
<script src="jquery.min.js">
$(Document).ready(function ()
{
var test = $("circuit").children(0).html;
alert(test);
}
);
</script>
Do this instead.
<script src="jquery.min.js"></script>
<script>
$(function(){
//stuff to run on load
});
</script>
Upvotes: 0
Reputation: 43
var test = document.getElementsByTagName("input")[0].innerHTML;
alert(test);
Upvotes: -1
Reputation: 2721
html() is a jQuery method, so you'll have to use the brackets :
//document not Document
$(document).ready(function (){
var test = $("circuit").html();
console.log(test);
});
Upvotes: 0