Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-07-19
5
279 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 83

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 83

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

856 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