Solved

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

Posted on 2014-07-19
5
273 Views
Last Modified: 2014-07-22
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
Comment
Question by:badwolfff
  • 2
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40206144
$(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
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40206174
Your 'result' has two 'href's and that's an error.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40206211
Dave, the jquery attr command over writes and does not add.   Are you seeing something different?

link
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40206513
I was talking about the original post.
0
 

Author Comment

by:badwolfff
ID: 40211708
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to dynamically set the form action using jQuery.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now