Getting HTML values from a page source using javascript [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to take html source lines from page source using javascript.
In my case the source is
<div id="green" class="orange">
Hello
</div>
<div id="red" class="blue">
Hello
</div>
In the above source, I have to take the id value as output, i.e "green" and "red" and not the text "hello" using Javascript, please help me with it.

You can access via class.
document.querySelector('div.orange').id

You could use jquery:
$('div').attr('id')

After Edit it is working example
To get orang class ID try this
$(".orange").attr('id');
And for Blue class try this one
$(".blue").attr('id');
Example on JSFiddle

Related

Find code in string by hovering on rendered HTML element? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
I'm trying to build custom Inspect Element, like browsers dev tools has.
It sounds simple:
You have string of code, like:
<h1>First header</h1>
<h1>Second header</h1>
Render this string in page.
Hover over second header.
How to get right position of <h1>Second header</h1> in the string?
Maybe I need to
Parse string to AST,
Add ID to every element.
Render a new version with ids.
Okay, we have right id of the element. But we need to find its position in string, not AST.
Anyway, how to solve this simplier? Also how can I do that for CSS/JS as well?

Can i change HTML structure with javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
I need to change 2 divs up and down by using javascript dom manipulation, without touching html.
<div class="div1"> this needs to go bottom</div>
<div class="div2"> and this needs to go up</div>
Is it possible to manipulate html structure with js?
You can do like this, swap the elements order in the parent node.
var div1 = document.getElementsByClassName("div1")[0];
var div2 = document.getElementsByClassName("div2")[0];
div2.parentNode.insertBefore(div2, div1);

Recreate behavior "background-attachment: fixed" with a div [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to recreate this effect that is achieved using the CSS property background-attachment:fixed, but I would recreate that effect using divs, I would recreate that on a h1 tag for example.
Is that possible?
Thanks
you have to customised http://tympanus.net/Blueprints/ScrollingLayout/js/cbpFixedScrollLayout.min.js
to achieve " I would recreate that effect using divs, I would recreate that on a h1 tag for example" instead "section" as it has below code
var cbpFixedScrollLayout=(function(){var a={$sections:$("#cbp-fbscroller > section")...
so it will always create this effect on section element.
so if you want to create it any other tag rather than section then you have yo customise above js, please try to implement it first .

how to read a text file and display it in html (angularjs) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am using angularjs and i have a terms of use document in a text file which i was to render into html. Any recommendations on how to read that text file and display it using html or display it to the user? Thanks
Simplest way is using ng-include. If you need to use the line breaks in the text file within your view wrap in a <pre> tag
<h3>Terms</h3>
<ng-include src="'terms.txt'"></ng-include>
OR
<pre ng-include src="'terms.txt'"></pre>
DEMO

How to display data from database in to a webpage with a scroll bar below [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I created a page like this before, but I put the data from the database on a table because it don't have so many columns. But this time, I'm going to need a scroll bar bellow because there are so many columns I need to display. I don't know if I'm going to use CSS here or JavaScript. Please help thanks btw.
Try this:table{width:100%;white-space : nowrap;overflow-x: scroll;} You can set height and width of your choice.
<div style="width=300px;overflow:scroll">
<table></table>
</div>

Categories