Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

How do I insert a piece of html code inside an html tag using jquery?

Hi,

I have a line of HTML code as follows:
<a href="test.html" title="home">CLICK</a>

Open in new window


I would like to insert the following code before ">CLICK":
data-tip="Pause Video" href="javascript:void(0);" onclick="pauseBgVideo();"

Open in new window


so that the result is like this:
<a href="test.html" title="home" data-tip="Pause Video" href="javascript:void(0);" onclick="pauseBgVideo();">CLICK</a>

Open in new window



I am using jQuery. How do I achieve this?

thanks in advance
0
badwolfff
Asked:
badwolfff
  • 2
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
$(function(){
$('#test').attr('data-tip','Pause Video').attr('href','javascript:void(0);').attr('onclick','pauseBgVideo();');
});

Open in new window


<a id="test" href="test.html" title="home">CLICK</a>

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
Your 'result' has two 'href's and that's an error.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Dave, the jquery attr command over writes and does not add.   Are you seeing something different?

link
0
 
Dave BaldwinFixer of ProblemsCommented:
I was talking about the original post.
0
 
badwolfffAuthor Commented:
I've tried the code and it doesn't work.
I've left it on the site for the moment.
I am trying to see if I can find a workaround too.

thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now