How can we concatenate two strings using jQuery?

<p style="">To concatenate two strings use the + concatenation operator. You can try to run the following code to learn how to concatenate two strings using jQuery &minus;</p><h2 style="">Example</h2><pre class="demo-code notranslate language-javascript" data-lang="javascript">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js&quot;&gt;&lt;/script&gt; &nbsp; &nbsp; &lt;script&gt; &nbsp; &nbsp; $(function(){ &nbsp; &nbsp; &nbsp; $(&quot;a&quot;).click(function(){ &nbsp; &nbsp; &nbsp; &nbsp; var id= $(&quot;.id&quot;).html(); &nbsp; &nbsp; &nbsp; &nbsp; $(&#39;.myclass&#39;).html(&quot;&lt;br&gt;&lt;div class=&#39;new&#39; id=&#39;&quot; + id + &quot;&#39;&gt;Hello&lt;/div&gt;&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); &nbsp; &nbsp; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &nbsp; &nbsp;&lt;div class=&quot;new&quot;&gt; &nbsp; &nbsp; &nbsp;&lt;a href=&quot;#&quot;&gt;Click me&lt;/a&gt; &nbsp; &nbsp; &nbsp;&lt;div class=&quot;myclass&quot;&gt;&lt;/div&gt; &nbsp; &nbsp; &nbsp;&lt;div class=&quot;id&quot;&gt;Tutorialspoint&lt;/div&gt; &nbsp; &nbsp;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre>

Updated on: 2026-03-11T20:40:49+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements