dom - How to insert a piece of code programmatically using jQuery? -
I am learning jQuery and I would like to use it to solve the old problem I have a piece of HTML code program I want to use jQuery to add. What I need to do: To create a jQuery function, all elements / objects are inside "code">
"When my function gets the
img
object, then I would like to put img
inside another div
. To clarify things, assume that my work code :
lt; img height = "200" width = "300" src = "image -2.jpg "title =" my image 1 "class =" alignonone Car-media wp-image-25 "> em> This is my image! ; p> Advertising Ready for Advertising In addition to this, Lt; / p & gt; & lt; img height = "400" width = "250" src = "image-2.jpg" title = "My image 2" class = " Alignment size-medium WP-image-25 "> em> This is another image! I would like to write a jQuery function that changes it to :
This is my image! & Lt; / Em> & Lt; P & gt; Advertising Ready for Advertising In addition to this, you live your life completely during your lifetime. & Lt; / P & gt; & Lt; Div class = "main-image" & gt; & Lt; Img height = "100" width = "200" src = "image-2.jpg" title = "my image 2" class = "attachment-single-post-image wp-post-image" & gt; & Lt; / Div & gt; & Lt; Em> This is another image! & Lt; / Em> & Lt; P & gt; Advertising Ready for Advertising In addition to this, you live your life completely during your lifetime. & Lt; / P & gt; & Lt; / Div & gt;
Then, "basically" what do i want to do:
- between all
img
objects & Lt; Div class = "main-image" & gt;
and & lt; / Div & gt;
; -
img
to the class attachment-single-post-image wp-post-image
; - Change the
img
height to 100
; - Change the
img
width to 300
.
this is :)
I do not know if my explanation is clear. Unfortunately I'm not a "native" English speaker.
entry Var img = $ ("img", searchScope) .attr ("height", 100) .attr ("width", 300) .removeClass () .addClass ("attachment- single-post-image WP-post-image" ) .wp ("
Comments
Post a Comment