Question

In: Computer Science

Q: Provide the expression to create an object collection of all objects referenced by the CSS...

Q: Provide the expression to create an object collection of all objects referenced by the CSS selector div#intro p?

Solutions

Expert Solution

Selector div#intro p means

Div is tag used an d html

#intro is the id used in the html code

p is again the paragraph tag of html

Now we want all the objects referenced by this selector id  using HTML DOM

So we use querySelectorAll() method   returns a collection of an element's child elements that matches a specified CSS selector i,e id or class , in form of a static single object

Steps

1. Give your div tag a id let's say divid

2. Define many element inside div inside p tag with id as intro as specified by you like

<div id="divid">

<p id ="intro "> My first id reference using intro <p>

<p id ="intro "> My Second id reference using intro <p>

</div>

and so on as many as you want

3. Now we to access all in form of a object collectively so use querySelectorAll() along with getElementById()

like this

var x = document.getElementById("divid").querySelectorAll("p#intro");

X contains all the objects that are referenced by id as intro inside div and p tag and you can access them like you access elements of any static object in HTML so X[0] will be represent first id reference and X[1] Second id reference and so on

Now using that you can do whatever you like to do

like for example

x[0].style.fontSize = "20px";

X[1].style.color="red";

So above changes will be applied only to specified Id and object reference and you can have a collection of all objects in one object only .

Thank You Please Upvote if you like it


Related Solutions

JAVASCRIPT Create an array of 5 objects named "movies" Each object in the movies array, should...
JAVASCRIPT Create an array of 5 objects named "movies" Each object in the movies array, should have the following properties: Movie Name Director Name Year Released WasSuccessful (this should be a boolean and at least 2 should be false) Genre Loop through all of the objects in Array If the movie is successful, display all the movie information on the page. These movies were a success: Title: Forrest Gump Year Realeased: 1994 Director: Robert Zemeckis Genre: Comedy
Write a for-each loop that prints all of the Student objects in an ArrayList<student> object called...
Write a for-each loop that prints all of the Student objects in an ArrayList<student> object called roster. Write this piece in Java. Write the correct code to execute.
Create 1 HTML page and 1 CSS file for all the styles. Your html page will...
Create 1 HTML page and 1 CSS file for all the styles. Your html page will be a small gallery of images using the Polaroid style. The page should have at least 1 row of 3 images. You can choose any theme of images. Don't pick random images, make them all have a theme. Add an h1 tag for the header of your page. Style the h1 tag with a color, size, and font family. Include a paragraph tag under...
Q.3.1 Provide a definition for Criminology. (5) Q.3.2 Differentiate between crime and deviance. (10) Q.3.3 Create...
Q.3.1 Provide a definition for Criminology. (5) Q.3.2 Differentiate between crime and deviance. (10) Q.3.3 Create a diagram to show the cycle of violence. (10) Q.3.4 Outline some of the general traits of transnational organised crime. (10) Q.3.5 List Syke’s and Matza’s FIVE neutralisation techniques and provide an example of each. (10)
1. Provide a regular expression that describes all bit-strings that length is at least one and...
1. Provide a regular expression that describes all bit-strings that length is at least one and at most three. 2. Provide a regular expression that describes all bit strings with odd length.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT