Jquery tutorial (9) using Java Script (jquery) to implement a rounded border

Source: Internet
Author: User

When I see these htmlSource codeI found this is suitable for writing a jquery tutorial-using the wrap (), prepend (), and append () functions.

Here is the original htmlCode, We will start from here:

<DivClass="Dialog"> <DivClass="HD"> <DivClass="C"> </Div> <DivClass="BD"> <DivClass="C"> <DivClass="S"> <Main content goes here> </div> <DivClass="Ft"> <DivClass="C"> </Div>

How can we use jquery to streamline this code?

First, we need a "Hook", a special HTML element, an ID, or an object name-to tell jquery's processing target.

Now we have changed it to the following:

<Div class = "roundbox"> <main content goes here> </div> next, we use jquery to add the remaining code:

 
$(Document).Ready(Function(){$("Div. roundbox").Wrap('<Div class = "dialog">'+'<Div class = "BD">'+'<Div class = "C">'+'<Div class = "S">'+'</Div>'+'</Div>'+'</Div>' +
 '</Div>'  ) ; } ) ;
 
 

Where are other Div tags?

When you carefully observe the code, you will find that they all go to the JS Code. When the wrap function is executed, they will be nested inside the "hook Div.

A careful audience will find that I have missed some code. This is because the wrap () function in jquery requires that DIV labels must be strictly symmetric and nested to work.

Specifically, I removed the following two parts:

 
<DivClass="HD"> <DivClass="C"> </Div> <DivClass="Ft"> <DivClass="C"> </Div>

Integration of adding and preset

In the next step, we will use the prepend and append functions to add these two pieces of code to the DIV tag with the dialog Object Name, and use the "chained" method.

$('Div. Dialog').Prepend('<Div class = "HD">'+'<Div class = "C"> </div>'+'</Div>').Append('<Div class = "ft">'+'<Div class = "C"> </div>'+'</Div>');

Example and code

I have placed a demo page on the Internet for you to view. We recommend that you take a look at the source code of the page to understand the freshness and convenience that jquery brings to the page code.

These codes are from an article by schillmania. I personally recommend you download a zip package containing dotted images, which is very exquisite.

Do not use the rounded border of the image

There are many ways to achieve rounded border-some methods do not even require images.

On the jquery website, there is a plug-in used to create a border with no rounded corners. Although not suitable for everyone (or allProgram), But it is worth learning.

Let's take a look at its pretty code (in use ):

 
$(Document).Bind("Load", Function(){$("# Box1").Corner()});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.