Set the id of the picture in the field

hello.
There is only one picture in the {{图片}} field .
I want to set the “ID” element for the picture in the field.

I tried many methods from the internet and myself, but they all failed.
Until a method: I slice the html information of the {{图片}} field.
Get n letters, and remove the < img src= " at the beginning and the " > at the end.

As shown in the following figure.


var image = document.createElement(“img”)
image.src=a3
// Can set the id element

I think my method is not simple.
If there is a more convenient html operation, can you express it?
I can teach myself this method.

o(∩_∩)o

you don’t have to just use getElementById! You can use getElementsByTagName or use a css selector like this:

function getsrc(){
  return document.querySelector("#image100 img").src
}
3 Likes

yes.
It work now.
Thank you so much.
Have a great day.
:smiling_face_with_three_hearts:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.