D3.js selection.property() Function
source link: https://www.geeksforgeeks.org/d3-js-selection-property-function/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
D3.js selection.property() Function
Last Updated: 23-08-2020The selection.property() function is used to set or change the property and value of a particular element. The value of a particular property can be deleted by setting its value to null.
Syntax:
selection.property(name[, value]);
Parameters: This function accept two parameters as mentioned above and described below:
- name: The name of the property to set.
- value: The property value to be set.
Return Value: This function does not return any value.
Example 1:
filter_none
edit
close
play_arrow
link
brightness_4
code
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
path1tent
=
"width=device-width, initial-scale=1.0"
>
</
script
>
</
head
>
<
body
>
<
div
>
<
input
type
=
"text"
>
</
div
>
<
script
>
// Sets value property of the the input tag
var input = d3.select("input")
.property("value", "some value from input");
var text = document.querySelector("input");
// Value from input
console.log(text.value);
</
script
>
</
body
>
</
html
>
Output:
Example 2:
filter_none
edit
close
play_arrow
link
brightness_4
code
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
path1tent
=
"width=device-width, initial-scale=1.0"
>
</
script
>
</
head
>
<
body
>
<
div
>
<
input
type
=
"checkbox"
class
=
"checkbox"
name
=
""
id
=
""
>checkbox<
br
>
<
button
>Click me</
button
>
</
div
>
<
script
>
function func() {
// Sets checked and value property
// of the the checkbox
var chk = d3.select(".checkbox").property(
"value", "some value from checkbox");
var chk = d3.select(".checkbox")
.property("checked", true);
var text = document.querySelector(".checkbox");
// Value from checkbox
console.log(text.value);
console.log(text.checked);
}
let btn = document.querySelector("button");
btn.addEventListener("click", func);
</
script
>
</
body
>
</
html
>
Output:
-
Before clicking the click me button:
-
After clicking the click me button:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to [email protected]. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Be the First to upvote.
No votes yet.
first_page D3.js log.rangeRound() Function last_page D3.js selection.text() Function
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK